Overview
This node allows you to interact with MongoDB databases using the Mongoose Object Data Modeling (ODM) library. Specifically, the Create operation enables you to create a new document in a specified MongoDB collection by defining the schema and providing the document data.
Common scenarios where this node is beneficial include:
- Adding new user profiles or records into a MongoDB collection.
- Inserting log entries or event data dynamically.
- Creating configuration or metadata documents in a structured way.
For example, you can define a schema for a "users" collection with fields like name, email, age, and created_at, then use this node to insert new user documents conforming to that schema.
Properties
| Name | Meaning |
|---|---|
| Database | The name of the MongoDB database to connect to. Leave empty to use the default from credentials. |
| Collection | The name of the MongoDB collection where the document will be created. |
| Schema Definition | JSON object defining the Mongoose schema for the collection. Specifies field names and types. |
| Document | JSON object representing the document data to create in the collection. |
Output
The output is an array of items, each containing a json property with the newly created document as stored in MongoDB. The document reflects the inserted data including any default values or transformations applied by Mongoose.
Example output structure:
{
"json": {
"_id": "60d5ec49f1a4c12d4c8b4567",
"name": "John Doe",
"email": "john@example.com",
"age": 30,
"created_at": "2023-01-01T00:00:00.000Z"
}
}
No binary data output is produced by this operation.
Dependencies
- Requires a valid connection to a MongoDB instance accessible via a connection string.
- Uses Mongoose ODM internally to manage schema definitions and interactions.
- Requires an API key credential or similar authentication configured in n8n to connect securely to MongoDB.
- The node supports multi-database connections if configured.
Troubleshooting
Common Issues
- Connection errors: If the node cannot connect to MongoDB, verify the connection string, network accessibility, and that MongoDB is running.
- Authentication failures: Check username, password, and authentication database settings.
- Schema definition errors: Invalid JSON or unsupported schema types in the schema definition may cause errors.
- Document format issues: Ensure the document JSON matches the schema and contains valid data types.
Common Error Messages
"MongoDB connection error": Indicates failure to establish a connection; check connection details and server status."MongoDB authentication failed": Credentials are incorrect or insufficient permissions."Invalid JSON format": The provided schema or document JSON is malformed."Limit exceeds maximum allowed": Not applicable for create but relevant for other operations; ensure limits are within safe bounds.
To resolve these, double-check all input parameters, credentials, and network configurations.
Links and References
- Mongoose Documentation — For schema definitions and model usage.
- MongoDB Manual — Official MongoDB documentation.
- n8n Documentation — For general guidance on creating and configuring nodes.