MongoDB Update

This Snap updates documents in a MongoDB collection and supports the upsert capability.

Overview

You can use this Snap to update documents in a MongoDB collection. It also supports the upsert capability.


MongoDB Update Snap in pipeline

Supported Accounts

  • This is a Write-type Snap.

Prerequisites

None.

Limitations and known issues

None.

Snap views

Type Description Examples of upstream and downstream Snaps
Input This Snap has exactly one document input view. Mapped data to evaluate expression properties and/or to update documents in a MongoDB collection. Each input document produces one document at the output view or the error view.
Output

Optional. This Snap has at most one document output view.

{
  "updatedDocuments": n,
  "matchedDocuments": m,
  "updateOfExisting": [true or false],
  "inserted": [true or false],
  "original": {input document}
}
  • In the above output:
    • updatedDocuments - is the number of MongoDB documents that are changed in the update query. The updateOfExisting is true if updatedDocuments is greater than 0.
    • matchedDocuments - is the number of MongoDB documents that match the query for potential change.
    • updateOfExisting - is true if there are any updatedDocuments, otherwise, false.

For example, if the existing documents are:

{
  "name": "Ralph",
  "color": "blue",
  "available": true
}
{
  "name": "Sally",
  "color": "blue",
  "available": false
}

And an update with query{} and input document of:

{
  "available": true
}

then the result will be as follows:

{
  "updatedDocuments": 1,
  "matchedDocuments": 2,
  "updateOfExisting": true,
  "inserted": false,
  "original": {
    {
      "available": true
    }
  }
}
Note:
  • Before introducing the matchedDocuments definition, the updateOfExisting would be true if matchedDocuments was greater than 0. Now, updateOfExisting is true if updatedDocuments is greater than 0.
  • The updateOfExisting output documents would be false if the update query matched documents, but didn't update documents.
Learn more about Error handling.

Snap settings

Field/Field set Description

Label

String
Required.Specify a unique name for the Snap. Modify this to be more appropriate, especially if there are more than one of the same Snap in the pipeline.

Default value: MongoDB - Update

Database name

String/Expression/ Suggestion

The database in which the collection is defined. If not specified, then the MongoDB account database will be used.

Default value: N/A

Example: assets

Collection name

String/Expression/ Suggestion

Required. Select or enter a MongoDB collection name.

Default value: N/A

Example: leads

Update query

String/Expression

Required. The update query represents the update query parameter. It is an expression that evaluates to an object or JSON string. When the expression evaluates to an object, only strict mode is supported. When the expression evaluates to a JSON string, both strict mode and mongo shell mode are supported. More information about MongoDB Extended JSON can be found here.

Example: (with '=' expression enabled)

$id represents an integer in this example.

{"id": {$lte: $id}}

or

'{"id": {$lte:' + $id + '}}'

Default value: N/A

Update operation

String/Expression/ Suggestion

The operation to be performed on the update query.

Default value: $set

Example: $min

Exclude list

Fieldset
List of input fields to exclude from the dataset.
Exclude field

String/Suggestion

The list of input fields that must be removed from the dataset before sending the dataset to MongoDB.

Default value: _id

Example: $ranking

Array filters

String/Expression

The filter conditions to determine the array elements you want to modify for the update operation. This field supports upstream values.

Default value: N/A

Example: $arrayFilters

Upsert

Checkbox

If selected, a document from the input view is inserted if no document in the collection matches the update query criteria.

Default status: Deselected

Update all that match

Checkbox

If selected, all documents in the collection that match the update query criteria are updated; otherwise the Snap updates only one document.

Default status: Selected

Pass through

Checkbox

If selected, the input document will be passed through to the output view under the key 'original'. The document will be passed to the Parameter output view, and it will also be passed to the Result Set output view if there is output sent from this view.

Default status: Selected

Number of retries

Integer/Expression

Specify the maximum number of attempts to be made to receive a response. The request is terminated if the attempts do not result in a response.

Note:
  • If the Number of retries value is set to 0 (the default value), the retry option is disabled, and the Snap does not initiate a retry. The pipeline will not attempt to retry the operation in case of a failure—any failure encountered during the database operation will immediately result in the pipeline failing without any retry attempts to recover from the errors.
  • If the Snap fails on all retries, it routes the last occurred exception to the error view.

Default value: 0

Example: 4

Retry interval (seconds)

Integer/Expression

Specify the time interval between two retry requests.

Default value: 1

Example: 5

Snap execution

Dropdown list
Choose one of the three modes in which the Snap executes. Available options are:
  • Validate & Execute: Performs limited execution of the Snap and generates a data preview during pipeline validation. Subsequently, performs full execution of the Snap (unlimited records) during pipeline runtime.
  • Execute only: Performs full execution of the Snap during pipeline execution without generating preview data.
  • Disabled: Disables the Snap and all Snaps that are downstream from it.

Default value: Execute only

Example: Validate & Execute

Note: The upstream schema suggest is only supported if the defined collection provides data. MongoDB does not provide a metadata API to describe the collection, so the SnapLogic platform looks at the data and derives the schema from it.