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

Update with positional operator does not update index

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: Major - P3 Major - P3
    • None
    • 2.2.2
    • None
    • ALL
    • Hide

      MongoDB shell version: 2.2.2
      connecting to: test
      > use test;
      switched to db test
      > db.test.insert({'array': [

      {'a': 'b'}

      ]});
      > db.test.find(

      {'array.a': 'b'}

      );
      { "_id" : ObjectId("50eae4ba4c08c986d476d22b"), "array" : [

      { "a" : "b" }

      ] }
      > db.test.update(

      {'array.a': 'b'}

      , {$set: {'array.$':

      {'a': 'c'}

      }});
      > db.test.find(

      {'array.a': 'c'}

      );
      { "_id" : ObjectId("50eae4ba4c08c986d476d22b"), "array" : [

      { "a" : "c" }

      ] }
      > db.test.ensureIndex(

      {'array.a': 1}

      );
      > db.test.find(

      {'array.a': 'c'}

      );
      { "_id" : ObjectId("50eae4ba4c08c986d476d22b"), "array" : [

      { "a" : "c" }

      ] }
      > db.test.update(

      {'array.a': 'c'}

      , {$set: {'array.$':

      {'a': 'b'}

      }});
      > db.test.find(

      {'array.a': 'b'}

      );
      // NOTE: Document NOT found here when it should be
      > db.test.dropIndex('array.a_1');

      { "nIndexesWas" : 2, "ok" : 1 }

      > db.test.find(

      {'array.a': 'b'}

      );
      { "_id" : ObjectId("50eae4ba4c08c986d476d22b"), "array" : [

      { "a" : "b" }

      ] }

      Show
      MongoDB shell version: 2.2.2 connecting to: test > use test; switched to db test > db.test.insert({'array': [ {'a': 'b'} ]}); > db.test.find( {'array.a': 'b'} ); { "_id" : ObjectId("50eae4ba4c08c986d476d22b"), "array" : [ { "a" : "b" } ] } > db.test.update( {'array.a': 'b'} , {$set: {'array.$': {'a': 'c'} }}); > db.test.find( {'array.a': 'c'} ); { "_id" : ObjectId("50eae4ba4c08c986d476d22b"), "array" : [ { "a" : "c" } ] } > db.test.ensureIndex( {'array.a': 1} ); > db.test.find( {'array.a': 'c'} ); { "_id" : ObjectId("50eae4ba4c08c986d476d22b"), "array" : [ { "a" : "c" } ] } > db.test.update( {'array.a': 'c'} , {$set: {'array.$': {'a': 'b'} }}); > db.test.find( {'array.a': 'b'} ); // NOTE: Document NOT found here when it should be > db.test.dropIndex('array.a_1'); { "nIndexesWas" : 2, "ok" : 1 } > db.test.find( {'array.a': 'b'} ); { "_id" : ObjectId("50eae4ba4c08c986d476d22b"), "array" : [ { "a" : "b" } ] }

    Description

      When performing an update using the positional operator on a field that contains an indexed subfield, the index is not updated. The result is that the document cannot be found via the index after the update. If you drop the index, the document can be found.

      Attachments

        Activity

          People

            thomas.rueckstiess@mongodb.com Thomas Rueckstiess
            dlongley Dave Longley
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: