MongoDB Pro icon

MongoDB Pro

Find, insert and update documents in MongoDB

Overview

This node enables interaction with MongoDB databases, supporting various operations on documents within specified collections. The Delete operation specifically allows users to remove multiple documents from a MongoDB collection based on a JSON-formatted query filter.

Typical use cases include:

  • Cleaning up outdated or irrelevant data by deleting documents matching certain criteria.
  • Automating data lifecycle management, such as removing records older than a specific date.
  • Bulk deletion of documents that meet complex conditions expressed in MongoDB's query language.

For example, you could delete all user documents where the birth date is before 1950 by specifying a query like:

{ "birth": { "$lt": "1950-01-01" } }

Properties

Name Meaning
Collection The name of the MongoDB collection from which documents will be deleted.
Delete Query (JSON Format) A JSON object representing the MongoDB query filter to select documents for deletion. For example: { "birth": { "$gt": "1950-01-01" } }

Output

The output is an array of JSON objects, each corresponding to the result of a delete operation for each input item. Each JSON object contains:

  • deletedCount: The number of documents that were deleted by the query.

Example output:

{
  "deletedCount": 5
}

This indicates that five documents matched the query and were removed from the collection.

Dependencies

  • Requires a connection to a MongoDB database.
  • Needs credentials providing access to the MongoDB instance (such as an API key or connection string).
  • The node expects the MongoDB Node.js driver to be available (bundled internally).
  • Proper configuration of the database name and authentication details is necessary.

Troubleshooting

  • Common issues:

    • Invalid JSON in the Delete Query property can cause parsing errors.
    • Incorrect collection names or database credentials will lead to connection failures.
    • Queries that do not match any documents will result in deletedCount being zero, which is expected behavior but might be confusing if unexpected.
  • Error messages:

    • "SyntaxError: Unexpected token ..." — Indicates malformed JSON in the query; verify and correct the JSON syntax.
    • "Database does not exist" — The specified database name is incorrect or inaccessible; check credentials and database name.
    • "Collection not found" — The collection name does not exist in the database; verify the collection name.
  • Resolution tips:

    • Use a JSON validator to ensure the query is well-formed.
    • Confirm database and collection names are correct and accessible with provided credentials.
    • Enable "Continue On Fail" option if you want the workflow to proceed despite individual errors.

Links and References

Discussion