// guides · n8n error index

n8n MongoDB node errors: Authentication failed, Invalid JSON and query fixes, 40 runs

Fix the n8n MongoDB node: Authentication failed (authSource), passwords with special characters, querySrv ENODATA, Invalid JSON in 'Query', unknown operator $oid, Find returning 0 items and Updates that change nothing. 40 real runs on n8n 2.43.7 and MongoDB 8.0.15.

Updated 2026-10-23 · about 10 minutes

Still stuck after these steps? Paste your exact n8n error and we'll reproduce it and email you the fix, free →

Steps

  1. Authentication failed? Check which database the user lives in

    In Values mode the credential always logged in against the admin database. Our user app, created in the shop database, failed with Authentication failed. even with Database set to shop (a wrong password gives the same message). Switching the credential to Connection String with mongodb://app:…@127.0.0.1:27018/?authSource=shop worked. It also works the other way: a connection string ending in /shop makes shop the login database, so our admin user (created in admin) failed with Authentication failed., even with the node's Database field set to admin. Leave the database out of the string path and put it in the Database field instead.

  2. Encode special characters in the password

    The Values credential pastes your password into a connection string without encoding it. Our password p@ss:w/rd failed with Unable to parse ss:w with URL. Use a Connection String credential and encode the characters yourself: @ as %40, : as %3A, / as %2F. With mongodb://special:p%40ss%3Aw%2Frd@127.0.0.1:27018 the same user connected.

  3. Fill in the port, and wait 30 seconds before calling it a hang

    An empty Port field makes n8n build a mongodb+srv:// string, which looks up DNS records: we got querySrv ENODATA _mongodb._tcp.127.0.0.1. Type 27017 (or your port). Network errors take about 30 seconds to show up (our failing runs took 32 to 34 seconds, a working one 2.5): a port with nothing listening gave The service refused the connection - perhaps it is offline, a host that doesn't answer gave connection timed out, and TLS turned on against a server without TLS gave Client network socket disconnected before secure TLS connection was established. localhost worked for us (the driver tried ::1, then 127.0.0.1).

  4. 0 items and no error? Check the database and collection names

    MongoDB doesn't complain about names that don't exist, it just returns nothing. An empty Database field read the test database, Shop instead of shop and the collection Orders instead of orders all gave 0 items with no error. When Find matches nothing, the node outputs 0 items and the next node doesn't run at all; see next node not running if the workflow must carry on.

  5. Write the query as strict JSON

    The Query field is parsed as JSON, not as MongoDB shell syntax. {status:'paid'} and a trailing comma both failed with Invalid JSON in 'Query'; {"status":"paid"} worked. An expression inside the string, {"status":"{{ $json.s }}"}, worked. With Query Parameters, the placeholder must be in quotes: {"status":$1} gave Invalid JSON in 'Query', {"status":"$1"} returned the right 2 items. For Aggregate, the query must be an array of stages, or you get Argument "pipeline" must be an array of aggregation stages.

  6. Match the stored type: _id, numbers and dates

    A 24-character hex string in _id at the top level was turned into an ObjectId and found the document. Extended JSON doesn't work: {"$oid": …} gave unknown operator: $oid, and any other string in _id gave input must be a 24 character hex string, 12 byte Uint8Array, or an integer. Types must match: "1001" (text) found nothing when orderId was stored as the number 1001. Dates are the worst case: a date string and {"$date": …} both returned 0 items with no error. What worked was the Aggregate operation with {"$match":{"$expr":{"$gte":["$createdAt",{"$toDate":"2026-10-15T00:00:00Z"}]}}}.

  7. After Update or Insert, check the data, not the green tick

    Update matches on the Update Key field with its type. Our item had orderId "1002" as text while the document had the number 1002: the node succeeded and output the item, but nothing changed. With Upsert on, it inserted a second document with the text "1002". Convert the key to the right type first (for example in an Edit Fields node). An item without the key field fails with Item is missing the updateKey field. On Insert, listed fields missing from the item are saved as null, text stays text ("12.50" is not a number) unless you convert it, Date Fields turns ISO strings into real dates, a unique index gives E11000 duplicate key error, and a read-only user gives not authorized on shop to execute command.

What we ran

On 23 October 2026 we ran 40 small workflows (Manual Trigger, sometimes a Code node, then the MongoDB node) with n8n execute on n8n 2.43.7 (MongoDB node version 1.5) against a local MongoDB 8.0.15 server with authentication on (port 27018, database shop). 15 runs tried credential variants, 25 tried Find, Aggregate, Insert and Update cases, and we checked the stored documents with a second MongoDB node. Every message below is copied from those runs.

SetupResult
Values credential, admin user (created in admin), Database shop, Find {"status":"paid"}2 items
Same, wrong passwordAuthentication failed.
Values credential, user app created in the shop database, Database shopAuthentication failed. (Values mode logs in against admin)
Connection String mongodb://app:…@127.0.0.1:27018/?authSource=shop2 items
Values credential, password p@ss:w/rdUnable to parse ss:w with URL
Connection String with the same password encoded: p%40ss%3Aw%2Frd2 items
Values credential, Port left emptyquerySrv ENODATA _mongodb._tcp.127.0.0.1 (empty port switches to mongodb+srv)
Port 27017, nothing listening thereThe service refused the connection - perhaps it is offline; the run took 32 seconds (a normal run took 2.5)
Host localhost instead of 127.0.0.12 items (the driver tried ::1, then 127.0.0.1)
Host that doesn't answer (192.0.2.10)connection timed out; the run took 32 seconds
Database field empty0 items, no error (the node read the test database)
Database Shop instead of shop0 items, no error
TLS turned on, server without TLSClient network socket disconnected before secure TLS connection was established; the run took 34 seconds
Connection String ending /shop, admin user, Database field emptyAuthentication failed. (/shop made shop the auth database)
Same string, Database field set to adminAuthentication failed.
Query {status:'paid'} (unquoted key, single quotes)Invalid JSON in 'Query'
Query {"status":"paid",} (trailing comma)Invalid JSON in 'Query'
Query {"_id":"652f1a2b3c4d5e6f70818283"} (24-character hex string)1 item: the string was turned into an ObjectId
Query {"_id":{"$oid":"652f…"}}unknown operator: $oid
Query {"_id":"1001"}input must be a 24 character hex string, 12 byte Uint8Array, or an integer
Query {"orderId":"1001"}, stored as the number 10010 items, no error
Collection Orders, stored as orders0 items, no error
Query {"createdAt":{"$gte":"2026-10-15"}}, stored as a Date0 items, no error
Query with {"$date":"2026-10-15T00:00:00Z"}0 items, no error
Aggregate [{"$match":{"$expr":{"$gte":["$createdAt",{"$toDate":"2026-10-15T00:00:00Z"}]}}}]3 items, the right ones
Query {"status":"{{ $json.s }}"} (expression)2 items
Query {"status":$1} with Query ParametersInvalid JSON in 'Query'
Query {"status":"$1"} with Query Parameters2 items
Find with no match, then a Code node0 items; the next node did not run
Find {}, Sort {"total":-1}, Limit 1The order whose total was the text "12.50" came first, above the number 99
Aggregate with one stage as an object, not an arrayArgument "pipeline" must be an array of aggregation stages
Aggregate with an array of stages1 item {"_id": "paid", "n": 2}
Insert orderId,zip,total,createdAt, Date Fields createdAt, zip "007", total "12.50"Saved; createdAt became a Date, zip stayed "007", total stayed the text "12.50"
Insert fields orderId,customer, status, item has only orderIdSaved with customer and status set to null
Insert into customers (unique index on email), existing emailE11000 duplicate key error collection: shop.customers index: email_1 dup key: { email: "ana@example.com" }
Insert with a user that has only the read rolenot authorized on shop to execute command { insert: "orders", …
Update Key orderId, item orderId "1002" (text), stored as the number 1002The node succeeded and output the item, but the document was not changed
Same with Upsert onA second document was inserted with orderId "1002" (text) and status shipped
Update Key orderId, item without an orderId fieldItem is missing the updateKey field
Update Key _id, item _id "abc"input must be a 24 character hex string, 12 byte Uint8Array, or an integer

Good to know

What we didn't test

FAQ

Why does the n8n MongoDB node say Authentication failed?

Either the password is wrong or n8n logs in against the wrong database. In Values mode it uses admin, so a user created in another database fails. Use a Connection String with ?authSource=yourdb, and don't end the string with /yourdb if the user lives in admin.

How do I use a password with @, : or / in the n8n MongoDB credential?

The Values credential doesn't encode it (we got Unable to parse ss:w with URL). Use a Connection String credential and encode the characters: @ as %40, : as %3A, / as %2F.

Why does the n8n MongoDB Find return no items?

In our tests: a wrong-case database or collection name, an empty Database field (it reads test), a number stored as a number but searched as text, or a date compared with a string. None of these give an error.

What does Invalid JSON in 'Query' mean in n8n MongoDB?

The Query field must be strict JSON: double quotes around keys and strings, no trailing commas, and query parameter placeholders in quotes ("$1").

Why doesn't the n8n MongoDB Update change anything?

The Update Key value has a different type than the stored one, for example text "1002" against the number 1002. The node still reports success, and with Upsert on it inserts a duplicate. Convert the value first.

Related guides

New guides

Still stuck on your n8n error?

Paste the exact error and say what the workflow should do. We reproduce it on a real n8n install and email you the fix or a working workflow, usually within 24h. Free while we're in beta.

We'll only email you about your error and TaskToAgent.