Forum Discussion

ccorbin_pwc's avatar
ccorbin_pwc
New Contributor
7 years ago

MongoDB Update Query Expression

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

  • tstack's avatar
    tstack
    Former Employee

    Have you tried writing the object literal directly instead of trying to build a string? For example:

    { _runId: _parentRunId, "$set": { documentsExpected: parseInt(_documentCount) } }
    

    (I’m assuming you need the document count as a number and not a string.)

    • tstack's avatar
      tstack
      Former Employee

      Can you provide some more details. Did it error out? Or, did it run and not do what you wanted?

  • ccorbin_pwc's avatar
    ccorbin_pwc
    New Contributor

    Yup, I can provide more details… I can’t read 😖

    The field name in my collection was “runId”, not “_runId”…

    Been looking right at it for hours!

    • aleung's avatar
      aleung
      Contributor III

      so I assume it is now working right?

      • ayush_vipul's avatar
        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.

        Regards
        Ayush