cancel
Showing results for 
Search instead for 
Did you mean: 

MongoDB Update Query Expression

ccorbin_pwc
New Contributor

I have a child pipeline, which contains a MongoDB Update Snap, and I am trying to have the Update Query be an expression so I can take into account parameters passed down to the child pipeline.

The documents in the MongoDB Collection I am targeting, have a unique index on a field named “runId”, and so I am trying to match on this, and where found update another value in the document “documentsExpected”, again from another parameter. Below is what I tried as my expression, but it is choking.

Is what I am attempting possible? If so, where am I going wrong with the expression?

“{ _runId:” + _parentRunId + “}, { $set: { documentsExpected:” + _documentCount + " } }"

8 REPLIES 8

so I assume it is now working right?

ayush_vipul
New Contributor III

Facing the same issue.

using the following as query { entityId: $original.EntityId , "$set": { comments: "documentCount" } }

it validates successfully but when executing getting following error.

Failure: Failed to update documents in the MongoDB collection: uiEventsPushed, Reason: Write failed with error code 2 and error message ‘unknown top level operator: $set’, Resolution: Please address reported issue.

image

Regards
Ayush

This property is only for the query portion of the operation, whereas $set is something that would be used in the update part of the operation. In other words, the property is used to find the docs in the collection to be updated, not how to update them. The snap will construct the update as a $set with the contents of the incoming document. So, you’d want the document coming into the snap to have a “comments” field with the new value.

ayush_vipul
New Contributor III

yes.

So in my current scenario i wish to filter a document/row in a collection and then add a new key - comments and its value.

Can you suggest a way i can achieve the same.