Delete documents from a MongoDB collection

This example pipeline demonstrates how to delete existing documents from a MongoDB collection, insert new documents, and then delete documents based on a query condition.


MongoDB Delete Example Pipeline

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.


    MongoDB Delete - Step 1

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

    JSON Generator configuration

  3. Insert the documents into the collection name, mongodb_collection2 using the MongoDB Insert Snap.

    MongoDB Insert configuration

  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.


    MongoDB Delete query configuration

  5. Validate the pipeline.
    The successful execution of the pipeline displays the output preview showing that four documents that satisfy the delete query are deleted.
    MongoDB Delete output

To successfully reuse pipelines:
  1. Download and import the pipeline into SnapLogic.
  2. Configure Snap accounts as applicable.
  3. Provide pipeline parameters as applicable.