I would like to know the correct way to send operators, in my example case, $addToSet when using the MongoDB update node. None of my attempts were successful.
What is the error message (if any)?
No errors, it’s just being inserted according to the default format (str, Object, etc).
I don’t think there is a way to do it with the MongoDB node in n8n. The type of call it makes requires a document with concrete values, not MongoDB functions/operators.
As a workaround, you can:
Read the document in
Change the array/set value in a similar way to what $addToSet does
Update the document
If you have a document in a collection named TestAddToSetWorkaround with the following content:
{
_id: ObjectId('68220786603c3f574d8d0d75'),
documentKey: '1234',
otherField1: 'leave this alone',
arrayFieldToAlter: [
'keep this'
],
otherField2: 'leave this alone too'
}
This workflow would give you a working “starting point” with the steps to add a new, unique value to the arrayFieldToAlter array element of the document.
Thank you! Even though it wasn’t the solution I was hoping for, it was still very helpful to learn about this limitation. I’ll submit a feature request for it. I think this would be relevant information to include in the documentation as well.