MongoDB - Update
In this article
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. 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:
|
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
Asterisk (*): Indicates a mandatory field.
Suggestion icon (): Indicates a list that is dynamically populated based on the configuration.
Expression icon (): Indicates whether the value is an expression (if enabled) or a static value (if disabled). Learn more about Using Expressions in SnapLogic.
Add icon (): Indicates that you can add fields in the field set.
Remove icon (): Indicates that you can remove fields from the field set.
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: N/A | String/Expression/Suggestion | Select or enter a MongoDB collection name. |
Update query*
Default value: N/A
{"id": {$lte: $id}} or '{"id": {$lte:' + $id + '}}' | 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.
|
Update operation Default Value: $set | String/Expression/Suggestion | Specify the operation to be performed on the update query.
|
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 | 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 | 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 | Checkbox | Select this checkbox to pass the input document through to the output view under the key '
|
Number of retries Default Value: 0 | 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. |
Retry interval (seconds) Default Value: 1 | Integer/Expression | Specify the time interval between two retry requests. |
Snap execution
Default Value: 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:
Downloads
Have feedback? Email documentation@snaplogic.com | Ask a question in the SnapLogic Community
© 2017-2024 SnapLogic, Inc.