Versions Compared

Key

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

On this Page

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

Snap type:

Write


Description:

This Snap updates one or more 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
  • Expected input: a map data to evaluate expression properties and/or to update documents in a MongoDB collection
  • Expected output

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

Code Block
{
  "name": "Ralph",
  "color": "blue",
  "available": true
}
{
  "name": "Sally",
  "color": "blue",
  "available": false
}

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

Code Block
{
  "available": true
}

then the result will be as follows:

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

$id represents an integer in this example.

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

or

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


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


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

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

Attachments
uploadfalse
oldfalse
patterns*.slp, *.zip

Insert excerpt
MongoDB Snap Pack
MongoDB Snap Pack
nopaneltrue