Versions Compared

Key

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

On this PageIn 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.

...

Expected upstream Snaps: Any Snap with document output view

...

Expected downstream Snaps: Any Snap with document input view

...

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

Code Block 

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

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:

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

Required. The name

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

The database that the collection is defined in. If not specified, then the MongoDB account database

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.

Example:  assets

Collection name

Required.

Collection name*

Default Value:

[None]  
 

 N/A
Example: leads

String/Expression/Suggestion

Select or enter a MongoDB collection name.

 
 

Update query*

 

Default value:N/A
Example:

 leads

Default: [None]  
 

Update query

Required.


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

More information

Learn more about MongoDB Extended JSON

can be found hereDefault value: [None]

.

 

Update operation

Default Value: $set
Example

(with '=' button pressed/expression enabled) 

$id represents an integer in this example.

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

or

Code Block
'{"id": {$lte:' + $id + '}}'
When selected, inserts

$min

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
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: $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.

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, updates

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. 

Default value: Not Selected

Update all that match

 

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:

  SelectedIf selected,

Selected

Pass through

Checkbox

Select this checkbox to pass the input document

will be passed

through to the output

views

view under the key 'original'. The document

will be

is passed to the Parameter output view, and it will also be passed to the Result Set output view if

there

output is

output

sent from this view.

Snap execution

Default

value

Value:

  Selected

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

...

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.

...

On validation, you can see that the record with id = equals to 1 having with multiple elements is updated based on the matched conditions.

MongoDB - Update output

MongoDB - Find output

Image RemovedImage Removed

Example #1

...

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.

 

Using Configure the JSON Generator Snap , we are passing the values with the data to be updated to the MongoDB collections. 

...

In Configure the MongoDB Update Snap settings, we specify with the collection name, Sample data, to be updated with the values just passed from the upstream JSON Generator Snap. The update query condition 

...

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

...