Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

In this article

Table of Contents
maxLevel2
excludeOlder Versions|Additional Resources|Related Links|Related Information

...

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

  • Min: 1

  • Max: 1

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

  • Min: 0

  • Max: 1

Any Snap with document input view.

Paste code macro
languagejson
{
      "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:

paste-code-macro
languagejson
{
  "name": "Ralph",
  "color": "blue",
  "available": true
}
{
  "name": "Sally",
  "color": "blue",
  "available": false
}

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

paste-code-macro
languagejson
{
  "available": true
}

then the result will be as follows:

paste-code-macro
languagejson
{
  "updatedDocuments": 1,
  "matchedDocuments": 2,
  "updateOfExisting": true,
  "inserted": false,
  "original": {
    {
      "available": true
    }
  }
}
Info
  • 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.

...

[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.

...

InputThis 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.

ErrorThis 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:

  • Stop Pipeline Execution: Stops the current pipeline execution when the Snap encounters an error.

  • Discard Error Data and Continue: Ignores the error, discards that record, and continues with the rest of the records.

  • Route Error Data to Error View: Routes the error data to an error view without stopping the Snap execution.

Learn more about Error handling in Pipelines.


Snap Settings

Info
  • Asterisk (*): Indicates a mandatory field.

  • Suggestion icon ((blue star)): Indicates a list that is dynamically populated based on the configuration.

  • Expression icon ((blue star)): Indicates whether the value is an expression (if enabled) or a static value (if disabled). Learn more about Using Expressions in SnapLogic.

  • Add icon ((blue star)): Indicates that you can add fields in the field set.

  • Remove icon ((blue star)): Indicates that you can remove fields from the field set.

Field Name

Field Type

Description

Label*

Default ValueMongoDB - Update
ExampleMongoDB - 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
Exampleassets

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
Example: leads

String/Expression/Suggestion

Select or enter a MongoDB collection name.

Example:  leads

Default: [None]  
 

...

Update query

...

 
 

Update query*

 

Default value:N/A
Example:
(with '=' expression enabled) 

$id represents an integer in this example.

Code Block
{"id": {$lte: $id}}

or

Code Block
'{"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

...

.

...

 

...

$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
Example$min

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
Example: $ranking

 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
Example:

...

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 'original'. The document

...

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
nameSnap Execution
pageSOAP Execute

...

Multiexcerpt include macro
nameExecution_Detail_Write
pageSOAP 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

Examples

Example #1

...

Execute only
Example: Validate & Execute

Dropdown list

Select 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.

Examples

Update records using array filters

This example pipeline below demonstrates how to use the Array filters field to update records with filter conditions.

...

Download this pipeline.

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.

 Image Modified

...

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:

Image Removed

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
namedownload_instructions
pageOpenAPI

Attachments
uploadfalse
oldfalse
patterns*.slp, *.zip

Insert excerpt
MongoDB Snap Pack
MongoDB Snap Pack
nopaneltrue