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

findandmodify with query containing $lt causes positional ($) operator mismatch

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major - P3 Major - P3
    • None
    • None
    • None
    • None
    • Ubuntu 9.10 (on VMWare 6.5.1 under Windows 7)

    Description

      Bugfix #SERVER-1095 works only for straightforward usage.
      We faced that adding $lt condition on integer field to the query of findandmodify operation causes $-operator mismatch.
      Here is some code to reproduce the bug:

      > db.test.insert( {PhoneNumber:"12345678", MessageParts:[

      {PartID:"a", Status:0, Timestamp:123456}

      ,

      {PartID:"b", Status:0, Timestamp:123456}

      ]} )
      > db.test.find()
      { "_id" : ObjectId("4c03d543299e2826314acf56"), "PhoneNumber" : "12345678", "MessageParts" : [

      { "PartID" : "a", "Status" : 0, "Timestamp" : 123456 }

      ,

      { "PartID" : "b", "Status" : 0, "Timestamp" : 123456 }

      ] }

      // Note that we try to conditionally update the second part with ID = "b". In this case item should be updated.

      > db.runCommand({findandmodify:"test", query:{PhoneNumber:"12345678", "MessageParts.PartID":"b", "MessageParts.Timestamp":{ $lt:123459 }},
      ... update:{ $set:

      {"MessageParts.$.Status": 1, "MessageParts.$.Timestamp":123460}

      }})
      {
      "value" : {
      "_id" : ObjectId("4c03d543299e2826314acf56"),
      "PhoneNumber" : "12345678",
      "MessageParts" : [

      { "PartID" : "a", "Status" : 0, "Timestamp" : 123456 }

      ,

      { "PartID" : "b", "Status" : 0, "Timestamp" : 123456 }

      ]
      },
      "ok" : 1
      }

      // Unexpected behaviour: another item is updated.

      > db.test.find()
      { "_id" : ObjectId("4c03d543299e2826314acf56"), "PhoneNumber" : "12345678", "MessageParts" : [

      { "PartID" : "a", "Status" : 1, "Timestamp" : 123460 }

      ,

      { "PartID" : "b", "Status" : 0, "Timestamp" : 123456 }

      ] }

      // without conditions ($lt) everything works fine
      > db.runCommand({findandmodify:"test", query:

      {PhoneNumber:"12345678", "MessageParts.PartID":"b"}

      ,
      ... update: { $set:

      {"MessageParts.$.Status":2}

      } })
      {
      "value" : {
      "_id" : ObjectId("4c03d543299e2826314acf56"),
      "PhoneNumber" : "12345678",
      "MessageParts" : [

      { "PartID" : "a", "Status" : 1, "Timestamp" : 123460 }

      ,

      { "PartID" : "b", "Status" : 0, "Timestamp" : 123456 }

      ]
      },
      "ok" : 1
      }
      > db.test.find()
      { "_id" : ObjectId("4c03d543299e2826314acf56"), "PhoneNumber" : "12345678", "MessageParts" : [

      { "PartID" : "a", "Status" : 1, "Timestamp" : 123460 }

      ,

      { "PartID" : "b", "Status" : 2, "Timestamp" : 123456 }

      ] }
      >

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved: