MOngodb Node in n8n failing to update documents with data from google sheet

  • Hello, I’m facing an issue with the MongoDB node in my n8n workflow that is failing to update documents. Here’s the detailed scenario:

Scenario Overview:

I am building an n8n workflow that performs the following steps:

  1. Search MongoDB for documents that meet specific criteria (i.e., non-empty documents).
  2. Retrieve these documents from MongoDB.
  3. For each document, search for a matching value (agent_name) in a Google Sheets file and retrieve the corresponding IP address.
  4. Update the MongoDB documents by setting the agent_ip field with the retrieved IP address from Google Sheets.

Issue Description:

The MongoDB node is unable to update the documents as intended.

Details of My Workflow:

After retrieving the data from Google Sheets, the MongoDB node is supposed to update the document by setting the agent_ip field, but the update is not happening.

My Setup:

I am using the following MongoDB node parameters:

Operation: Update
Update key: agent_ip
Fields: agent_ip (to be updated with the value from Google Sheets)

Current Errors Encountered:

  1. MongoDB Update Issue: The update operation does not update the document as expected.

It looks like your topic is missing some important information. Could you provide the following if applicable.

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

n8n Version

1.60.1

Hey @naihazafar , could you also share your workflow here to better understand the flow (you did it in our ticketing system).

Tip for sharing information

Pasting your n8n workflow


Ensure to copy your n8n workflow and paste it in the code block, that is in between the pairs of triple backticks, which also could be achieved by clicking </> (preformatted text) in the editor and pasting in your workflow.

```
<your workflow>
```

That implies to any JSON output you would like to share with us.

Make sure that you have removed any sensitive information from your workflow and include dummy or pinned data with it!


It sounds like the error “Google Sheets quota exceeded” happens because you retrieve GSheet data over and over with each record from MongoDB. That is an unnecessary consumption of resources. The better approach to retrieve all the GSheet records just once and have it compared with each MongoDB record in the workflow itself.

There is an option to run a node just once as shown below

Hello,

I’ve resolved the “Google Sheets quota exceeded” issue by ensuring the Google Sheets data is only retrieved once and then compared with each MongoDB record in the workflow.

However, I’m still encountering a problem with the MongoDB node not updating the document data as expected. Could you help identify why this might be happening?

Thanks!

n8nVersion: 1.62.4

  • platform: npm
  • nodeJsVersion: 20.18.0
  • database: sqlite
  • executionMode: regular
  • concurrency: 999
  • license: community
  • consumerId: 00000000-0000-0000-0000-000000000000

storage

  • success: all
  • error: all
  • progress: false
  • manual: true
  • binaryMode: filesystem

pruning

  • enabled: true
  • maxAge: 168 hours
  • maxCount: 2500 executions

Generated at: 2024-10-11T20:46:57.150Z

Hey @naihazafar , please, paste your workflow here.

Tip for sharing information

Pasting your n8n workflow


Ensure to copy your n8n workflow and paste it in the code block, that is in between the pairs of triple backticks, which also could be achieved by clicking </> (preformatted text) in the editor and pasting in your workflow.

```
<your workflow>
```

That implies to any JSON output you would like to share with us.

Make sure that you have removed any sensitive information from your workflow and include dummy or pinned data with it!


If you find it too complicated, do you want me to do it for you?

Would it be possible for you to resolve this in one meeting? If so, that would be great.

Hey @naihazafar , you seem to expect a free premium support. Sorry to disappoint you. We try our best in this forum. If you want us to help, please follow our guidance.

Here’s your workflow as you resist providing it in the forum yourself.

We will review it when we have an opportunity to do so.

Hey @naihazafar , I think the problem is with the way you provide the field name to update. Just the name is expected but you provided JSON. Also, the Update Key value does not sound right to me.

I would expect to see something like this like below provided MongoDB document has the field name “agent_name” and you want to update “agent_ip” in that document.

For this to work, the output of GSheet should have items containing the property

{
  "agent_ip" : "<SOME_IP>"
}


I have attempted to update the agent_ip of the document in the MongoDB node using this method, but I’m still unable to do so. Could you please assist me further with this issue?

Hey @naihazafar , for this to work, you need to have the matching keys. For example, in your last screenshot, your have agent_name as the Update Key. This key is used to locate the record you want to update. However, your input data has no such a key. As a result no document found to apply the update to.

Here’s a screenshot showing how it works. Let say you have a document

{
  "agent_name": "James",
  "agent_ip": "203.13.345.125",
  "location": "Boston",
  "something": 123
}

To update the key agent_ip with another value for the agent_name James, you have to have both keys in the input data. There could be more but the rest will be ignored.

Let’s change the IP to “203.13.50.123”. For that to happen, the input data as a minimum should be

{
  "agent_name": "James",
  "agent_ip": "203.13.50.123"
}

Hopefully this example helps you to configure your workflow correctly.

1 Like

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