I’m attempting to manipulate a MongoDB Database/Collection from within a workflow and having problems. I have precious little inexperience with databases.
I have automatic device creation working with a /register endpoint; works fine. From within my /register workflow I’m attempting to create a MongoDB document corresponding to the device using fields from the payload. I can create a document using a JSON payload with a unique _id with InsertOne “{ “_id”:”{{data.body.serialNumber}}", “Hello”:“World” }". The Hello:World pair will also be created in the document if it’s hard-coded as shown.
However, I would like to create a number of additional document fields from the payload but I can’t get this working. For instance I would like to iterate through “data.device.attributes” and create document fields for each of my attributes. How do I go about this? UpdateOne and UpdateMany complain of “E11000 duplicate key error” as though I’m attempting to create a new document when I use “{ “_id”: “{{data.body.serialNumber}}” }” in the Query Argument field of the MongoDB node. My understanding is that the first argument in the MongoDB workflow node is the document to update and the second argument are the field:value pair(s) to add to the document. Where’s my error?
With UpdateOne:
Query Argument: { “_id”: “{{data.body.serialNumber}}” }
Update to Apply: { “test” : “test” }
Should this not add a field:value pair “test”:“test” in the Query Argument’s document?
Jason