Kingfoodmart Mongoose icon

Kingfoodmart Mongoose

Interact with MongoDB using Mongoose ODM

Overview

This node allows interaction with MongoDB databases using the Mongoose Object Data Modeling (ODM) library. It supports a variety of operations such as creating, finding, updating, deleting documents, counting documents, and running aggregation pipelines on specified collections within a MongoDB database.

The "Delete One" operation specifically deletes a single document matching a given query from a specified collection. This is useful when you want to remove exactly one record that meets certain criteria, for example, deleting a user by their unique email address or removing an outdated log entry.

Practical examples:

  • Deleting a user account by user ID.
  • Removing a single product entry from an inventory collection.
  • Cleaning up one specific error log entry after it has been resolved.

Properties

Name Meaning
Database The name of the MongoDB database to connect to. Leave empty to use the default database from credentials.
Collection The name of the collection in the database where the delete operation will be performed.
Query A JSON object defining the MongoDB query filter to select the document to delete.
Schema Definition JSON definition of the Mongoose schema for the collection, specifying field types and structure.
Include Query Info Boolean flag indicating whether to include raw MongoDB query information in the response.
Options Additional options including:
- Limit Maximum number of results to return (not applicable for deleteOne).
- Skip Number of documents to skip (not applicable for deleteOne).
- Sort Sort order for results (not applicable for deleteOne).
- Select Fields Fields to include/exclude in results (not applicable for deleteOne).
- Upsert Whether to create a document if none matches (only relevant for update operations).
- Multi Whether to update multiple documents (only relevant for update operations).
- Query Timeout (Ms) Maximum time allowed for the query to run, in milliseconds.
- Debug Mode Enables Mongoose debug mode to log all MongoDB queries to the console.

Output

The output is a JSON object representing the result of the delete operation. It typically includes metadata about the deletion, such as the number of documents deleted.

If the "Include Query Info" option is enabled, the output also contains the original query and options used for the operation, providing transparency into what was executed.

Example output structure:

{
  "data": {
    "acknowledged": true,
    "deletedCount": 1
  },
  "query": { /* the query used */ }
}

No binary data output is produced by this node.

Dependencies

  • Requires a MongoDB instance accessible via a connection string.
  • Uses Mongoose ODM library for schema modeling and database operations.
  • Requires an API key credential or similar authentication token configured in n8n to connect securely to MongoDB.
  • Supports multi-database connections by resolving the correct database based on input parameters or credentials.

Troubleshooting

  • Connection errors: Errors like "MongoNotConnectedError", "Client must be connected", or connection timeouts indicate issues with the MongoDB connection string, network connectivity, or that the MongoDB server is not running. Verify connection details and ensure MongoDB is accessible.
  • Authentication failures: Messages mentioning "authentication failed" suggest incorrect username, password, or authentication source settings. Double-check credentials.
  • Host not found: Errors containing "ENOTFOUND" or "getaddrinfo" mean the hostname/IP address is invalid or unreachable. Confirm DNS and network settings.
  • Connection refused: "ECONNREFUSED" indicates MongoDB is not accepting connections on the specified port. Ensure the service is running and firewall rules allow access.
  • Invalid JSON format: If the query or schema JSON inputs are malformed, the node throws parsing errors. Validate JSON syntax carefully.
  • Limit exceeded: For operations supporting limits, setting a limit above 10,000 triggers an error for safety reasons.
  • Large result sets warning: When retrieving many documents, a console warning suggests adding indexes or refining filters to improve performance.

Links and References

Discussion