Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-16409

Updates against paths composed with array index notation and positional operator can insert an embedded document

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.6.4
    • Component/s: Write Ops
    • None
    • ALL

      Not sure if this is related to https://jira.mongodb.org/browse/SERVER-14886 or not, but updates to an embedded document in an array can cause an insertion to happen in 2.6.4 but the correct update in 2.4.10.

      db.test.insert({
        root: [
          {
            _id: "A",
            children: [
              {_id: "C", name: "Alice"}
            ]
          },
          {
            _id: "B",
            children: [
              {_id: "D", name: "Bob"}
            ]
          }
        ]
      })
      

      To update Bob's name to Carol, I can issue:

      db.test.update({"root._id": "B", "root.1.children._id": "D"}, {$set: {"root.1.children.$.name": "Carol"}})
      

      In 2.4, this update's Bob's name to Carol. In 2.6.4, this INSERTS Carol:

      mongos> db.test.find({}).pretty()
      {
      	"_id" : ObjectId("547f72c1e52e8693ed137ad6"),
      	"root" : [
      		{
      			"_id" : "A",
      			"children" : [
      				{
      					"_id" : "C",
      					"name" : "Alice"
      				}
      			]
      		},
      		{
      			"_id" : "B",
      			"children" : [
      				{
      					"_id" : "D",
      					"name" : "Bob"
      				},
      				{
      					"name" : "Carol"
      				}
      			]
      		}
      	]
      }
      

      Note that if you drop the

      {"root._id": "B"}

      part of the clause in the update, you get the 'The positional operator did not find the match needed from the query' error from SERVER-14886.

            Assignee:
            ramon.fernandez@mongodb.com Ramon Fernandez Marina
            Reporter:
            jonhyman Jon Hyman
            Votes:
            1 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: