-
Notifications
You must be signed in to change notification settings - Fork 53k
Closed
Labels
in linearIssue or PR has been created in Linear for internal reviewIssue or PR has been created in Linear for internal review
Description
Bug Description
The current implementation of Update and Find and Update in the MongoDB node improperly updates data in sub-documents. Sub-document data gets replaced when the update is made, even with Use Dot Notation enabled and specified in the Fields parameter. This effectively makes MongoDB unusable with n8n due to the potential loss of data.
To Reproduce
Please use the n8n workflow below to reproduce the improper behavior. This workflow inserts a sub-document into mongodb, then attempts to update the sub-document using dot notation.
{
"nodes": [
{
"parameters": {},
"type": "n8n-nodes-base.manualTrigger",
"typeVersion": 1,
"position": [
0,
0
],
"id": "7d69c983-ccdf-4683-b6ab-c4ef275e4763",
"name": "When clicking ‘Test workflow’"
},
{
"parameters": {
"mode": "raw",
"jsonOutput": "{\n \"subdocs\": {\n \"subdoc1\": \"test1\",\n \"subdoc2\": \"test2\"\n }\n}",
"options": {
"dotNotation": false
}
},
"type": "n8n-nodes-base.set",
"typeVersion": 3.4,
"position": [
220,
0
],
"id": "003fbf30-9939-41bc-af78-7c699a29e253",
"name": "Edit Fields"
},
{
"parameters": {
"mode": "raw",
"jsonOutput": "={\n \"subdocs.subdoc3\": \"test3\"\n}",
"includeOtherFields": true,
"include": "selected",
"includeFields": "_id",
"options": {
"dotNotation": true
}
},
"type": "n8n-nodes-base.set",
"typeVersion": 3.4,
"position": [
660,
0
],
"id": "2cdd0597-f2c5-4f9e-b8af-480f7a012056",
"name": "Edit Fields1"
},
{
"parameters": {
"operation": "update",
"collection": "test",
"updateKey": "_id",
"fields": "subdocs.subdoc3",
"options": {
"useDotNotation": true
}
},
"type": "n8n-nodes-base.mongoDb",
"typeVersion": 1.1,
"position": [
880,
0
],
"id": "f2841e0a-ad57-4e27-8718-cc9dc3f732c3",
"name": "MongoDB1",
"credentials": {
"mongoDb": {
"id": "3fhYRcj1gel0JE75",
"name": "MongoDB (VPF)"
}
}
},
{
"parameters": {
"operation": "insert",
"collection": "test",
"fields": "={{ $json.keys().join() }}",
"options": {}
},
"type": "n8n-nodes-base.mongoDb",
"typeVersion": 1.1,
"position": [
440,
0
],
"id": "2de4a6e4-ed40-4414-85d3-00b5f49a9750",
"name": "MongoDB",
"credentials": {
"mongoDb": {
"id": "3fhYRcj1gel0JE75",
"name": "MongoDB (VPF)"
}
}
}
],
"connections": {
"When clicking ‘Test workflow’": {
"main": [
[
{
"node": "Edit Fields",
"type": "main",
"index": 0
}
]
]
},
"Edit Fields": {
"main": [
[
{
"node": "MongoDB",
"type": "main",
"index": 0
}
]
]
},
"Edit Fields1": {
"main": [
[
{
"node": "MongoDB1",
"type": "main",
"index": 0
}
]
]
},
"MongoDB": {
"main": [
[
{
"node": "Edit Fields1",
"type": "main",
"index": 0
}
]
]
}
},
"pinData": {},
"meta": {
"templateCredsSetupCompleted": true,
"instanceId": "3c32212ff3fb61b79fe9be2c4bdcf031204cac2996c00031e19e3c96dc2e40b4"
}
}
Expected behavior
'subdoc3' should have been appended to 'subdocs' instead of over-writing 'subdocs'.
Operating System
MacOS 15.4.1
n8n Version
1.90.2
Node.js Version
22.15.0
Database
SQLite (default)
Execution mode
main (default)
Metadata
Metadata
Assignees
Labels
in linearIssue or PR has been created in Linear for internal reviewIssue or PR has been created in Linear for internal review