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 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, you could delete all documents where the "birth" field is greater than "1950-01-01" by specifying a JSON query { "birth": { "$gt": "1950-01-01" } }.

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 by the operation.

Example output:

[
  {
    "deletedCount": 5
  }
]

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

Dependencies

  • Requires a MongoDB database connection configured via credentials that provide necessary authentication details.
  • The node uses the official MongoDB Node.js driver to connect and perform operations.
  • The node expects valid MongoDB connection parameters, either as a connection string or separate configuration fields.
  • No additional external services are required beyond access to the MongoDB instance.

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 follows MongoDB query syntax.
  • Connection Issues: Errors related to connecting to MongoDB usually indicate incorrect credentials, network issues, or the specified database/collection does not exist.
  • No Documents Deleted: If deletedCount is zero, it means no documents matched the query. Verify the query conditions.
  • Permission Denied: Insufficient permissions on the MongoDB user may cause errors when attempting to delete documents.
  • To handle errors gracefully, enable the node's "Continue On Fail" option to prevent workflow interruption and capture error messages in the output.

Links and References

Discussion