MongoDB Pro icon

MongoDB Pro

Find, insert and update documents in MongoDB

Overview

This node enables updating a search index in a MongoDB collection using the Atlas Search feature. It connects to a specified MongoDB database and collection, then updates an existing search index with a new definition. This operation is useful when you want to modify how your data is indexed for full-text search or vector search capabilities without recreating the index from scratch.

Common scenarios:

  • Refining search relevance by adjusting analyzers or tokenizers in the index definition.
  • Adding or modifying fields included in the search index.
  • Changing index types (e.g., from text search to vector search) to support advanced search features.

Practical example:
You have a product catalog stored in MongoDB and use Atlas Search indexes to enable fast product searches. After adding new product attributes, you update the search index definition to include these attributes, improving search accuracy and user experience.


Properties

Name Meaning
Collection The name of the MongoDB collection where the search index exists and will be updated.
Index Name The exact name of the search index to update.
Index Definition A JSON object defining the new configuration of the search index. This includes type and detailed settings such as analyzers, mappings, or vector search parameters.

Output

The node outputs an array of JSON objects corresponding to each input item processed. For the "Update Search Index" operation, each output JSON object contains a key named after the index updated, with a boolean value true indicating success. For example:

[
  {
    "mySearchIndex": true
  }
]

If an error occurs during the update, the output JSON will contain an error field with the error message.


Dependencies

  • Requires a connection to a MongoDB instance that supports Atlas Search indexes.
  • Needs credentials with sufficient permissions to update search indexes on the target MongoDB cluster.
  • The node expects the MongoDB driver and n8n workflow environment to be properly configured.

Troubleshooting

  • Common issues:

    • Invalid or malformed JSON in the "Index Definition" property can cause parsing errors.
    • Specifying a non-existent collection or index name will result in errors.
    • Insufficient permissions on the MongoDB user may prevent updating the index.
    • Network connectivity issues to the MongoDB cluster.
  • Error messages and resolutions:

    • "error": "some message" — Check the error message for details; often indicates invalid input or permission problems.
    • "Database does not exist" — Verify the database name in credentials.
    • "Collection not found" — Ensure the collection name is correct and exists.
    • "Failed to parse JSON" — Validate the JSON syntax in the index definition.
    • "Unauthorized" — Confirm the API key or credentials have the required privileges.

Use the "Continue On Fail" option to handle errors gracefully and process remaining items.


Links and References

Discussion