Mongo Db Operations icon

Mongo Db Operations

MongoDB Operations

Overview

This node performs various MongoDB operations on specified collections within a database. It connects to a MongoDB instance using provided credentials and executes commands such as updating documents, finding documents, aggregating data, inserting new documents, replacing existing ones, or deleting documents.

The Delete One operation specifically deletes a single document matching a given query from a specified collection. This is useful for removing unwanted or obsolete records based on criteria defined by the user.

Common scenarios:

  • Removing a user record that matches certain conditions.
  • Deleting outdated logs or entries from a collection.
  • Cleaning up test data after processing.

Example:
You want to delete one document from the "users" collection where the field status equals "inactive". You provide the collection name "users" and a query { "status": "inactive" }. The node will connect to MongoDB and delete one matching document.

Properties

Name Meaning
Collection The name of the MongoDB collection where the deletion will occur.
Query (JSON Format) A JSON-formatted MongoDB query specifying which document to delete. For example, { "age": { "$lt": 18 } } deletes a document where the age is less than 18.

Output

The output of the Delete One operation returns the input items unchanged in the json output field. There is no explicit confirmation or metadata about the deletion result included in the output JSON.

  • The output JSON corresponds directly to the input data items.
  • No binary data is produced by this operation.

Dependencies

  • Requires a valid connection to a MongoDB database.
  • Needs an API key credential or authentication token configured in n8n to connect securely to the MongoDB instance.
  • The node uses the official MongoDB Node.js driver internally to perform operations.

Troubleshooting

  • Common issues:

    • Invalid or malformed JSON in the query property can cause parsing errors.
    • Connection failures due to incorrect credentials or network issues.
    • Attempting to delete from a non-existent collection or with a query that matches no documents results in no changes but no error.
  • Error messages:

    • Errors related to invalid queries typically mention JSON parsing problems.
    • Authentication errors indicate issues with the provided credentials.
    • If the node throws an error and "Continue On Fail" is disabled, the workflow execution stops; enabling it allows the workflow to continue with error details in the output.
  • Resolution tips:

    • Validate JSON syntax carefully before running.
    • Verify MongoDB credentials and network access.
    • Use the MongoDB shell or another client to test queries independently.

Links and References

Discussion