MongoDB Tool + AI Agent - Update not working

Describe the problem/error/question

Using an AI Agent + MongoDB Tool with the Find And Update or Update function does not work. The failure happens regardless of the AI Agent being in charge of filing the updateKey, field or manual setup.
It looks like the AI Agent is not providing the input context required for the tool to work, i.e. there is no _id (id of the record to update in the database) passed to the MongoDB tool.

For example, asking in the chat “Can you update the contract “test” field and put “hello2” as a new value for the contract with “name”: “name1” ?” will find the correct record in the database and will attempt to update “test”: “hello2” but nothing happens in the database. The input of the MongoDB Update tool is :
{ "Update_Key": "669113cb318bc1105004a8e7", "Fields": "hello2" }

I believe the correct format should be:
{ "Update_Key": "_id", "Fields": "test" }
and that the _id and test are taken from the input context. But the input context is empty :frowning:

What is the error message (if any)?

No error message shown.

Please share your workflow

Share the output returned by the last node

[ { "output": "The \"test\" field has been successfully updated to \"hello2\" for the contract named \"name1\"." } ]
Although the update has not been performed.

Information on your n8n setup

  • n8n version: : 1.85.4
  • Database (default: SQLite): MongoDB
  • n8n EXECUTIONS_PROCESS setting (default: own, main): default
  • Running n8n via (Docker, npm, n8n cloud, desktop app): n8n cloud
  • Operating system:

Hi @searje,

you’re using $fromAI and asking the model to fill these out. It might help to provide model with a better prompting and description for each parameter. Also your MongoDB1 tool has empty query, is that intended?

Hi @oleg,

Thank you for your answer. The mongoDB1 only works with an empty JSON query and is able to return a specific documents when asking in the chat. When the query is set to " Defined automatically by the model" there is an error “”[object Object]" is not valid JSON".

For the update query, it looks like this tool only takes two inputs:

  • Update_Key
  • Fields

It is not clear to me if the model has to provide the Update_Key as a pair of key/value, for example
{
“Update_Key”: {“id”: “669113cb318bc1105004a8e7”},
“Fields”: “{"test":"hello3"}”
}
or just the Update_Key name, for example “id” and its value will be set by the Node using the input context.

I tried both approach by prompting more precisely and give examples, but I still can’t achieve a MongoDB update using this tool.

Thanks you for your assistance !

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.