On this Page
Table of Contents | ||||
---|---|---|---|---|
|
Snap type: | Write | |||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Description: | This Snap updates one or more documents in a MongoDB collection. It also supports the upsert capability.
For example, if the existing documents are:
And an update with query{} and input document of:
then the result will be as follows:
| |||||||||||||
Prerequisites: | [None] | |||||||||||||
Support and limitations: | Works in Ultra Task Pipelines. | |||||||||||||
Account: | This Snap uses account references created on the Accounts page of SnapLogic Manager to handle access to this endpoint. See MongoDB Account for information on setting up this type of account. | |||||||||||||
Views: |
| |||||||||||||
Settings | ||||||||||||||
Label | Required. The name for the Snap. You can modify this to be more specific, especially if you have more than one of the same Snap in your pipeline. | |||||||||||||
Database name | The database that the collection is defined in. If not specified, then the MongoDB account database will be used. Example: assets Default: [None] | |||||||||||||
Collection name | Required. Select or enter a MongoDB collection name. Example: leads Default: [None] | |||||||||||||
Update query | 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 '=' button pressed/expression enabled)
or
Default value: [None] | |||||||||||||
Update operation | Specifies the operation to be performed on the update query. Example: $min Default value: $set | |||||||||||||
Exclude list | Specifies the list of input fields that must be removed from the dataset before sending the dataset to MongoDB. Example: $ranking Default value: _id | |||||||||||||
Upsert | When selected, inserts a document from the input view if no document in the collection matches the update query criteria. Default value: Not Selected | |||||||||||||
Update all that match | When selected, updates all documents in the collection that match the update query criteria, otherwise updates only one. Default value: Selected | |||||||||||||
Pass through | If selected, the input document will be passed through to the output views 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 value: Selected | |||||||||||||
|
|
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 |
Examples
Example #1
In this example, we shall update the collection from an upstream Snap to the MongoDB table using the MongoDB Update Snap.
Using the JSON Generator Snap, we are passing the values to be updated to the MongoDB collections.
In the MongoDB Snap settings, we specify the collection name, Sample data, to be updated with the values just passed from the upstream JSON Generator Snap. The update query condition
"{field002:'"+$field002+"'}" is passed (with the expression enabled) to update the documents in the collection.
The successful execution of the pipeline displays the below output preview:
Example #2
This example pipeline performs the following tests:
deletes all documents in a collection
inserts three documents into the empty collection
updates two documents in the same collection
The pipeline is attached in the Downloads section below.
Downloads
Multiexcerpt include macro | ||||
---|---|---|---|---|
|
Attachments | ||||||
---|---|---|---|---|---|---|
|
Insert excerpt | ||||||
---|---|---|---|---|---|---|
|