Mongo DB OID icon

Mongo DB OID

Find, insert and update documents in MongoDB

Overview

This node allows users to interact with a MongoDB database by performing various operations such as finding, inserting, updating, deleting, and aggregating documents within specified collections. The "Delete" operation specifically enables the removal of multiple documents from a chosen MongoDB collection based on a user-defined query.

Common scenarios for using this node include:

  • Cleaning up outdated or irrelevant data in a MongoDB collection.
  • Automating deletion of records that meet certain criteria (e.g., removing users inactive since a specific date).
  • Managing data lifecycle by programmatically deleting documents matching complex queries.

For example, a user might delete all documents where the "birth" field is greater than "1950-01-01" by providing a JSON query specifying this condition.

Properties

Name Meaning
Collection The name of the MongoDB collection where the delete operation will be performed.
Delete Query (JSON Format) A JSON-formatted MongoDB query defining which documents to delete. For example: { "birth": { "$gt": "1950-01-01" } }

Output

The output is a JSON array containing an object with a single property:

  • deletedCount: The number of documents that were deleted as a result of the operation.

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, authenticated via credentials that provide access to the target database.
  • The node depends on the MongoDB Node.js driver and BSON utilities for parsing and handling MongoDB-specific data types.
  • Proper configuration of the MongoDB credentials within n8n is necessary, including either a connection string or detailed connection parameters.

Troubleshooting

  • Invalid Query Format: If the JSON query is malformed or contains invalid MongoDB operators, the node will throw an error. Ensure the query is valid JSON and uses correct MongoDB query syntax.
  • Connection Issues: Errors related to authentication or connectivity may occur if the provided credentials are incorrect or the database is unreachable. Verify the credentials and network accessibility.
  • Collection Does Not Exist: If the specified collection does not exist in the database, the operation may fail or delete zero documents. Confirm the collection name is correct.
  • Permission Denied: Insufficient permissions for the authenticated user to perform delete operations will cause errors. Check user roles and privileges in MongoDB.
  • Continue On Fail: If enabled, the node will return an error message in the output JSON instead of stopping execution when an error occurs.

Links and References

Discussion