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

findandmodify doesn't support positional ($) operator

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 1.5.2
    • Affects Version/s: 1.4.2
    • Component/s: None
    • Labels:
      None
    • Environment:
      Ubuntu 9.10 (on VMWare 6.5.1 under Windows 7)

      Please, consider the following use case:
      > use foo
      switched to db foo
      > db.test.insert({ Article : "Bla-bla", TagDesc : [

      {Name : "Nature", Rate: 10}

      ,

      {Name: "Culture", Rate : 2 }

      ] })
      > db.runCommand({ findandmodify : "test", query :

      { Article : "Bla-bla", "TagDesc.Rate" : 2 }

      , update : { $set :

      { "TagDesc.$.Name" : "Economics" }

      } })
      {
      "value" : {
      "_id" : ObjectId("4bda64d1967d194e851b03ed"),
      "Article" : "Bla-bla",
      "TagDesc" : [

      { "Name" : "Nature", "Rate" : 10 }

      ,

      { "Name" : "Culture", "Rate" : 2 }

      ]
      },
      "ok" : 1
      }

      server console output:
      Fri Apr 30 08:07:36 foo.$cmd Caught Assertion in update , continuing
      Fri Apr 30 08:07:36 update foo.test query:

      { _id: ObjId(4bda64d1967d194e851b03ed) }

      exception userassert:can't append to array using string field name 0ms

      The object was not changed
      > db.test.find()
      { "_id" : ObjectId("4bda64d1967d194e851b03ed"), "Article" : "Bla-bla", "TagDesc" : [

      { "Name" : "Nature", "Rate" : 10 }

      ,

      { "Name" : "Culture", "Rate" : 2 }

      ] }
      >

      Note that at this time we specified index of item manually instead of using positional operator ( "TagDesc.$.Name" -> "TagDesc.1.Name" ).
      And changes were applied successfully.
      > db.runCommand({ findandmodify : "test", query :

      { Article : "Bla-bla", "TagDesc.Rate" : 2 }

      , update : { $set :

      { "TagDesc.1.Name" : "Economics" }

      } })
      {
      "value" : {
      "_id" : ObjectId("4bda64d1967d194e851b03ed"),
      "Article" : "Bla-bla",
      "TagDesc" : [

      { "Name" : "Nature", "Rate" : 10 }

      ,

      { "Name" : "Culture", "Rate" : 2 }

      ]
      },
      "ok" : 1
      }
      > db.test.find()
      { "Article" : "Bla-bla", "TagDesc" : [

      { "Name" : "Nature", "Rate" : 10 }

      ,

      { "Name" : "Economics", "Rate" : 2 }

      ], "_id" : ObjectId("4bda64d1967d194e851b03ed") }
      >

            Assignee:
            mathias@mongodb.com Mathias Stearn
            Reporter:
            pmm PowerMeMobile
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: