0

I am attempting to write a query that removes the element from the array based on the messageId associated with said object in the array. This is submitted through curl hence the formatting, I've tried unsuccessfully a few different ways.

'{"collection":"someCollection",
             "database":"someDB",
             "dataSource":"someSource",
             "filter": { "serverID": "someServer" },
             "update":
                { "$pull": { "messages.messageId" : "VDFajqgcOQ" },
                { "messages.$.messageId" : "VDFajqgcOQ" }}}'

Curl response : malformed JSON string, neither array, object, number, string or atom, at character offset 0 (before "Invalid syntax error...") at /usr/bin/core_perl/json_pp line 59.

{"collection":"someCollection",
             "database":"someDB",
             "dataSource":"someSource",
             "filter": { "serverID": "someServer" },
             "update": { 
                 "$pull": { "messages.$.messageId" : "VDFajqgcOQ" }}}'

Failed to update document: FunctionError: write exception: write errors: [The positional operator did not find the match needed from the query.]

Structure of the Data

The first one is just not syntactically correct the second just doesn't work the way I'd expect.

2
  • You can try this syntax: { $pull: { messages: { messageId: "VDFajqgcOQ" } } }
    – prasad_
    Mar 29 at 4:06
  • Thank you for your reply. I was able to figure it out eventually and this indeed was the way to go about it.
    – NullWolf
    Mar 30 at 13:06

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.