[SERVER-29515] Invalid "cannot use part of (results of results.answers) to traverse elemt Created: 08/Jun/17  Updated: 27/Oct/23  Resolved: 08/Jun/17

Status: Closed
Project: Core Server
Component/s: Querying
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Lorne Schachter Assignee: Backlog - Query Team (Inactive)
Resolution: Works as Designed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
is related to SERVER-29526 Updating the specific array in nested... Closed
Assigned Teams:
Query
Operating System: ALL
Steps To Reproduce:

> db.survey.find()
{
  "_id": 1,
  "results": [
    {
      "item": "A",
      "score": 5,
      "answers": [
        "a1",
        "a2",
        "a3"
      ]
    },
    {
      "item": "B",
      "score": 8,
      "answers": [
        "a2",
        "a3",
        "a4"
      ]
    }
  ]
}
{
  "_id": 2,
  "results": [
    {
      "item": "C",
      "score": 8,
      "answers": [
        "a1",
        "a2"
      ]
    },
    {
      "item": "B",
      "score": 4,
      "answers": [
        "a1",
        "a2"
      ]
    }
  ]
}
 
> db.survey.update( {}, { $pullAll : {"results.answers": ["a3", "a4"]}}, { multi : true})
cannot use the part (results of results.answers) to traverse the element ({results: [ { item: "A", score: 5.0, answers: [ "a1", "a2", "a3" ] }, { item: "B", score: 8.0, answers: [ "a2", "a3", "a4" ] } ]})
WriteResult({
  "nMatched": 0,
  "nUpserted": 0,
  "nModified": 0,
  "writeError": {
    "code": 16837,
    "errmsg": "cannot use the part (results of results.answers) to traverse the element ({results: [ { item: \"A\", score: 5.0, answers: [ \"a1\", \"a2\", \"a3\" ] }, { item: \"B\", score: 8.0, answers: [ \"a2\", \"a3\", \"a4\" ] } ]})"
  }
})

Participants:

 Description   

Similar to SERVER-20171, except that client is trying to remove elements from arrays of arrays. There are only two documents in the collection



 Comments   
Comment by Tess Avitabile (Inactive) [ 08/Jun/17 ]

Correct, the syntax in the ticket would still be an error.

Comment by Lorne Schachter [ 08/Jun/17 ]

Tess,

That would be the new syntax, right?

Thanks,
Lorne

Comment by Tess Avitabile (Inactive) [ 08/Jun/17 ]

Yes, if I understand what they are trying to do, they could write

db.survey.update( {}, { $pullAll : {"results.$[].answers": ["a3", "a4"]}}, { multi : true})

Comment by David Storch [ 08/Jun/17 ]

justin.seyster tess.avitabile, your work on array updates will eliminate this limitation, correct?

Generated at Thu Feb 08 04:21:06 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.