Steps
Authentication failed? Check which database the user lives in
In Values mode the credential always logged in against the
admindatabase. Our userapp, created in theshopdatabase, failed withAuthentication failed.even with Database set toshop(a wrong password gives the same message). Switching the credential to Connection String withmongodb://app:…@127.0.0.1:27018/?authSource=shopworked. It also works the other way: a connection string ending in/shopmakesshopthe login database, so our admin user (created inadmin) failed withAuthentication failed., even with the node's Database field set toadmin. Leave the database out of the string path and put it in the Database field instead.Encode special characters in the password
The Values credential pastes your password into a connection string without encoding it. Our password
p@ss:w/rdfailed withUnable to parse ss:w with URL. Use a Connection String credential and encode the characters yourself:@as%40,:as%3A,/as%2F. Withmongodb://special:p%40ss%3Aw%2Frd@127.0.0.1:27018the same user connected.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 gotquerySrv ENODATA _mongodb._tcp.127.0.0.1. Type27017(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 gaveThe service refused the connection - perhaps it is offline, a host that doesn't answer gaveconnection timed out, and TLS turned on against a server without TLS gaveClient network socket disconnected before secure TLS connection was established.localhostworked for us (the driver tried ::1, then 127.0.0.1).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
testdatabase,Shopinstead ofshopand the collectionOrdersinstead ofordersall 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.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 withInvalid 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}gaveInvalid JSON in 'Query',{"status":"$1"}returned the right 2 items. For Aggregate, the query must be an array of stages, or you getArgument "pipeline" must be an array of aggregation stages.Match the stored type: _id, numbers and dates
A 24-character hex string in
_idat the top level was turned into an ObjectId and found the document. Extended JSON doesn't work:{"$oid": …}gaveunknown operator: $oid, and any other string in_idgaveinput must be a 24 character hex string, 12 byte Uint8Array, or an integer. Types must match:"1001"(text) found nothing whenorderIdwas 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"}]}}}.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 withItem 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 givesE11000 duplicate key error, and a read-only user givesnot 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.
| Setup | Result |
|---|---|
Values credential, admin user (created in admin), Database shop, Find {"status":"paid"} | 2 items |
| Same, wrong password | Authentication failed. |
Values credential, user app created in the shop database, Database shop | Authentication failed. (Values mode logs in against admin) |
Connection String mongodb://app:…@127.0.0.1:27018/?authSource=shop | 2 items |
Values credential, password p@ss:w/rd | Unable to parse ss:w with URL |
Connection String with the same password encoded: p%40ss%3Aw%2Frd | 2 items |
| Values credential, Port left empty | querySrv ENODATA _mongodb._tcp.127.0.0.1 (empty port switches to mongodb+srv) |
| Port 27017, nothing listening there | The 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.1 | 2 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 empty | 0 items, no error (the node read the test database) |
Database Shop instead of shop | 0 items, no error |
| TLS turned on, server without TLS | Client network socket disconnected before secure TLS connection was established; the run took 34 seconds |
Connection String ending /shop, admin user, Database field empty | Authentication failed. (/shop made shop the auth database) |
Same string, Database field set to admin | Authentication 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 1001 | 0 items, no error |
Collection Orders, stored as orders | 0 items, no error |
Query {"createdAt":{"$gte":"2026-10-15"}}, stored as a Date | 0 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 Parameters | Invalid JSON in 'Query' |
Query {"status":"$1"} with Query Parameters | 2 items |
| Find with no match, then a Code node | 0 items; the next node did not run |
Find {}, Sort {"total":-1}, Limit 1 | The order whose total was the text "12.50" came first, above the number 99 |
| Aggregate with one stage as an object, not an array | Argument "pipeline" must be an array of aggregation stages |
| Aggregate with an array of stages | 1 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 orderId | Saved with customer and status set to null |
Insert into customers (unique index on email), existing email | E11000 duplicate key error collection: shop.customers index: email_1 dup key: { email: "ana@example.com" } |
| Insert with a user that has only the read role | not authorized on shop to execute command { insert: "orders", … |
Update Key orderId, item orderId "1002" (text), stored as the number 1002 | The node succeeded and output the item, but the document was not changed |
| Same with Upsert on | A second document was inserted with orderId "1002" (text) and status shipped |
Update Key orderId, item without an orderId field | Item 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
- A wrong password and a user in the wrong login database give the same
Authentication failed., so check authSource before resetting passwords. - Other database nodes we tested the same way: Postgres, Postgres Trigger, MySQL and Redis. Every message from our tests is in the n8n error message index.
What we didn't test
- MongoDB Atlas and real
mongodb+srvclusters, replica sets, TLS with real certificates, the Delete, Find And Replace and Find And Update operations, and MongoDB versions other than 8.0.15.
Start from a working agent
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
- n8n MySQL node errors: Access denied, SSL and SQL fixes, 41 runs
- n8n Postgres node errors: connection, SQL and insert fixes, 33 runs
- n8n Supabase node errors: credentials, RLS and filter fixes, 41 runs
- n8n XML node not working: parse errors, one item vs array, attributes and Split Out, 39 runs
- n8n Sort node not sorting correctly: numbers, dates and nulls, 33 runs
New guides
- GitHub release notifications in Slack (any public repo, stable releases only)
- Send RSS feeds to Slack with a keyword filter (free, incoming webhook)
- Forward emails to a Slack channel (Gmail, Outlook, any IMAP), free with an incoming webhook
- n8n Google Sheets Trigger not working: not firing, activation errors and fixes