Can anyone teach me how to use Mongo db node (update)

Describe the problem/error/question

Can you provide a minimal, official example of how Update and Find and Update are intended to be configured when the value should be set to a constant (e.g., status=‘published’) but the Update Key is sourced from a previous node?

What I already tried:

  • Both Update and Find and Update operations, with Fixed mode for Update Key and Fields.​

  • Using topic_id (derived from _id) vs using _id directly as Update Key; results still showed no change in MongoDB even when the node output looked correct.​

  • Ensuring Fields only lists the key names (status) while the value is provided by the upstream item (status=‘published’); output looks fine but DB remains unchanged.​

  • Creating a new field (check=‘done’) via Edit Fields and updating it to verify the pipeline; output shows the new field but nothing changes in the database.​

  • Suspecting the extra quotes might be the culprit; the output sometimes shows a value like “\“68ed…\”” rather than a clean ‘68ed…’, indicating the value may be stringified or wrapped somewhere along the way.

What is the error message (if any)?

Please share your workflow

MongoDB (Find) → 2) Edit Fields (Set) → 3) MongoDB (Update) or MongoDB (Find and Update). In Edit Fields, I set topic_id = {{$json._id}} and status = published (Fixed), then in the MongoDB node I use Update Key and Fields in Fixed mode. Fields is status, and the input items show status: 'published' as expected, with topic_id values for each document.

{
  "nodes": [
    {
      "parameters": {},
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        -256,
        192
      ],
      "id": "8866a440-4bdf-4a2b-9840-651b7ba649c1",
      "name": "When clicking ‘Execute workflow’"
    },
    {
      "parameters": {
        "collection": "topics",
        "options": {}
      },
      "type": "n8n-nodes-base.mongoDb",
      "typeVersion": 1.2,
      "position": [
        -80,
        192
      ],
      "id": "1ec490ae-a661-4d93-aa91-1692a7bf94b3",
      "name": "Find documents",
      "credentials": {
        "mongoDb": {
          "id": "njCtaTcZ3aVlGEEw",
          "name": "MongoDB account"
        }
      }
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "85fec713-ecda-4db5-8202-0d4090dffc37",
              "name": "status",
              "value": "=published",
              "type": "string"
            },
            {
              "id": "2c77ab52-a1be-4170-bef6-dd651a9e9d16",
              "name": "topic_id",
              "value": "={{ $json._id }}",
              "type": "string"
            },
            {
              "id": "240093f6-e4fb-4d4f-b9f7-2f6159f92333",
              "name": "check",
              "value": "done",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        128,
        192
      ],
      "id": "3d8e9c39-3b2e-4eaa-b034-b8377faccc9b",
      "name": "Edit Fields1"
    },
    {
      "parameters": {
        "operation": "findOneAndUpdate",
        "collection": "topics",
        "updateKey": "={{ $('Find documents').item.json._id }}",
        "fields": "status",
        "upsert": true,
        "options": {}
      },
      "type": "n8n-nodes-base.mongoDb",
      "typeVersion": 1.2,
      "position": [
        320,
        192
      ],
      "id": "6e6c6209-123c-4b67-b7f7-df1a24c6ed9a",
      "name": "Find and update documents",
      "credentials": {
        "mongoDb": {
          "id": "njCtaTcZ3aVlGEEw",
          "name": "MongoDB account"
        }
      }
    }
  ],
  "connections": {
    "When clicking ‘Execute workflow’": {
      "main": [
        [
          {
            "node": "Find documents",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Find documents": {
      "main": [
        [
          {
            "node": "Edit Fields1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Edit Fields1": {
      "main": [
        [
          {
            "node": "Find and update documents",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {},
  "meta": {
    "templateCredsSetupCompleted": true,
    "instanceId": "8d1d58319b6c74a46621954479dd0f9e6ddeddf12fb7564609d3dcd2f09dd6ec"
  }
}

Share the output returned by the last node

No output data returned

n8n stops executing the workflow when a node has no output data. You can change this default behaviour via Settings > “Always Output Data”.

Information on your n8n setup

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

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