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 deletes some or all documents in a MongoDB collection.

  • 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, if any
  • Expected output:  Number of documents deleted {"deleted_documents": n}
Prerequisites:

[None]


Support and limitations:Ultra pipelines: Works Works in Ultra Pipelines.Spark mode: Not supported in /wiki/spaces/SD/pages/1437917 modeTask 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 at most one optional document input view.
Output

This Snap has at most one optional document output view.
The output document contains the number of documents deleted.
{"deleted_documents": n}

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 value:  [None]  
 

Collection name



Required. Select or enter a MongoDB collection name.
Example:  leads
Default value:  [None]  
 

Delete query

The delete query represents the remove query parameter. It is an expression that evaluates to an object or JSON string. If no delete query is defined, then all records will be removed from the collection. 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]


Allow delete all


If this property is selected and the Delete query is empty, all documents are deleted from the selected collection.
If not selected and the Deleted query property is empty, the Snap execute successfully with an output document:
{"deleted_documents": 0}

Default value:  Not 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 pipeline, we shall:

  • Delete the existing documents from a MongoDB collection
  • Supply new documents in a JSON format using the JSON Generator Snap.
  • Insert the documents into the collection
  • Delete the required documents providing a delete query 

 


1. Using the MongoDB Delete Snap, delete the existing documents from the collection, mongodb_collection2. The respective output preview displays that the three documents are deleted from the collection: 














2. Supply the new documents to be inserted into the MongoDB collection through the JSON Generator Snap.

  


  



3. Insert the documents into the collection name, mongodb_collection2 using the MongoDB Insert Snap. The respective output preview displayed is as below: 

4. Delete the required documents from the collection, mongodb_collection2, by giving the delete query, {age:{ $gte:30}. This would delete all the documents where the age of a person is greater than or equal to 30 years.

5. The successful execution of the pipeline displays the below output preview (Four Documents that satisfy the delete query are deleted):


 


Insert excerpt
MongoDB Snap Pack
MongoDB Snap Pack
nopaneltrue