MongoDB - Delete

MongoDB - Delete

On this Page

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:

Works in Ultra Tasks.

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:

Input

This 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}

Error

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

{"id": {$lte: $id}}

or

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



Number of retries




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.

  • If the Number of retries value is set to 0 (the default value), the retry option is disabled, and the Snap does not initiate a retry. The pipeline will not attempt to retry the operation in case of a failure—any failure encountered during the database operation will immediately result in the pipeline failing without any retry attempts to recover from the errors.

  • If the Snap fails on all retries, it routes the last occurred exception to the error view.

Default Value0
Example: 4

Retry interval (seconds)

Specify the time interval between two retry requests.



Default Value: 1
Example: 5



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