Mongo Db Operations icon

Mongo Db Operations

MongoDB Operations

Insert

AI-generated

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 inserting documents, updating, finding, aggregating, replacing, or deleting records.

The Insert operation specifically allows users to insert one or multiple JSON documents into a chosen MongoDB collection. This is useful for adding new data entries in bulk or individually, such as importing user profiles, logging events, or storing configuration settings.

Practical example: You have a list of customer records in JSON format and want to add them all to your "customers" collection in MongoDB. Using this node’s Insert operation, you can pass the array of JSON documents, and it will insert them efficiently.

Properties

Name Meaning
Collection The name of the MongoDB collection where the document(s) will be inserted.
Document (JSON Format) The JSON-formatted document data to insert into the collection. Can contain any valid JSON object representing the record fields and values.

Output

The output is a JSON array containing the documents that were inserted into the MongoDB collection. Each item corresponds to one inserted document, reflecting the exact data sent to the database.

No binary data output is produced by this operation.

Dependencies

  • Requires a MongoDB database accessible via a connection string.
  • Needs an API key credential or authentication token configured in n8n to connect securely to the MongoDB instance.
  • Uses MongoDB Node.js driver internally to perform database operations.

Troubleshooting

  • Common issues:

    • Invalid JSON format in the "Document" property will cause parsing errors.
    • Incorrect collection names or missing collections may result in insertion failures.
    • Connection errors if the MongoDB credentials or connection string are incorrect or the database is unreachable.
  • Error messages:

    • JSON parse errors: Ensure the document input is valid JSON.
    • Authentication errors: Verify the API key or credentials used for MongoDB access.
    • Network or timeout errors: Check network connectivity and MongoDB server status.
  • To handle errors gracefully, enable the node’s "Continue On Fail" option to allow workflow execution to proceed even if some inserts fail.

Links and References

Discussion