...
In this article
Table of Contents | ||||
---|---|---|---|---|
|
...
Snap type:
Write
...
Description:
...
Overview
You can use this Snap to update documents in a MongoDB collection. It also supports the upsert capability.
...
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
...
Snap Type
The MongoDB - Update Snap is a Write-type Snap.
Prerequisites
None.
Support for Ultra Pipelines
Works in Ultra Task Pipelines.
Limitations and Known Issues
None.
Snap Views
Type | Format | Number of Views | Examples of Upstream and Downstream Snaps | Description |
---|---|---|---|---|
Input | Document |
| Any Snap with document output view. | A map data to evaluate expression properties and/or to update documents in a MongoDB collection |
...
Expected output:
...
. Each input document produces one document at the output view or the error view. | ||||||||||||||||||||||||||
Output | Document |
| Any Snap with document input view. |
For example, if the existing documents are:
And an update with query{} and input document of:
then the result will be as follows:
|
...
[None]
...
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.
...
Input | This Snap has one document input view. Each input document produces one document at the output view or the error view. |
---|---|
Output | This Snap has one optional document output view. |
Error | This Snap has at most one document error view and produces zero or more documents in the view. |
...
Settings
Label
...
Error | Error handling is a generic way to handle errors without losing data or failing the Snap execution. You can handle the errors that the Snap might encounter while running the Pipeline by choosing one of the following options from the When errors occur list under the Views tab. The available options are:
Learn more about Error handling in Pipelines. |
Snap Settings
Info |
---|
|
Field Name | Field Type | Description |
---|---|---|
Label* Default Value: MongoDB - Update | String | Specify a 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 |
...
Default Value: N/A | String/Expression/Suggestion | Specify the database in which the collection is defined. If you do not specify one, the database configured in the MongoDB Account will be used. |
...
Collection name* Default Value: |
...
Collection name
...
N/A | String/Expression/Suggestion | Select or enter a MongoDB collection name. |
Example: leads
Default: [None]
...
Update query
...
| ||||||
Update query*
Default value:N/A
or
| Textbox | 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. |
...
Learn more about MongoDB Extended JSON |
...
. |
...
|
...
$id
represents an integer in this example.
Code Block |
---|
{"id": {$lte: $id}} |
or
Code Block |
---|
'{"id": {$lte:' + $id + '}}' |
Default value: [None]
...
Update operation Default Value: $set | String/Expression/Suggestion | Specify the operation to be performed on the update query. |
...
Example: $min
Default value: $set
...
Exclude list | List of input fields to exclude from the dataset. | |
Exclude field Default Value: _id | String/Suggestion | Specify the list of input fields that must be removed from the dataset before sending the dataset to MongoDB. |
Array filters Default Value:N/A |
...
Default value: _id
...
Upsert
...
$arrayFilters | Expression/Textbox | Specify the filter conditions to determine the array elements you want to modify for the update operation. This field supports upstream values. |
Upsert
Default Value: Deselected | Checkbox | Select this checkbox to insert a document from the input view if no document in the collection matches the update query criteria. |
...
|
Update all that match Default Value: |
...
Selected |
...
Update all that match
Checkbox | Select this checkbox to update all documents in the collection that match the update query criteria |
...
; otherwise the Snap updates only one document. |
Pass through Default value: |
...
Selected |
...
Pass through
...
Checkbox | Select this checkbox to pass the input document |
...
through to the output |
...
view under the key ' |
...
is passed to the Parameter output view, and it will also be passed to the Result Set output view if |
...
output is |
...
sent from this view. |
Snap execution Default |
...
Value: |
...
Multiexcerpt include macro | ||||
---|---|---|---|---|
|
...
Multiexcerpt include macro | ||||
---|---|---|---|---|
|
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
...
Execute only | Dropdown list | Select one of the three modes in which the Snap executes. Available options are:
|
Examples
Update records using array filters
This example pipeline below demonstrates how to use the Array filters field to update records with filter conditions.
...
Step 1: Configure the MongoDB - Find Snap to search all the records with record id =1.
...
Step 2: Configure the Mapper Snap with the employees' salaries to be updated for employees, employees_1, and employees_2 elements within the record id=1.
...
Step 3: Configure the MongoDB - Update Snap with the following filter conditions:
{{elem.dept = QA} and {elem.age = 32}}
{{elem1.dept = QA} or {elem1.age = 32}}
{{elem2.dept = QA} or {elem2.salary <= 25000}}
...
On validation, you can see that the record with id equals to 1 with multiple elements is updated based on the matched conditions.
...
Update collection in MongoDB
This example pipeline demonstrates how to update the collection from an upstream Snap to the MongoDB table using the MongoDB Update Snap.
...
Configure the JSON Generator Snap
...
with the data to be updated to the MongoDB collections.
...
...
Configure the MongoDB Update Snap
...
with 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
...
Downloads
Multiexcerpt include macro | ||||
---|---|---|---|---|
|
Attachments | ||||||
---|---|---|---|---|---|---|
|
Insert excerpt | ||||||
---|---|---|---|---|---|---|
|