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

equality operators with object values delete all documents where field is a document or array of documents

    • Type: Icon: Bug Bug
    • Resolution: Works as Designed
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Querying, Sharding
    • None
    • ALL
    • Hide
          var mongod = MongoRunner.runMongod();
          let db = mongod.getDB("test");
          let coll = db.getCollection("coll");
      
          assert.commandWorked(coll.insert({ a: { "y": 1 }}));
          assert.commandWorked(coll.insert({ a: { "y": 2 }}));
          assert.commandWorked(coll.insert({ a: { "x": 1 }}));
          assert.commandWorked(coll.insert({ a: { "x": 2 }}));
          assert.commandWorked(coll.insert({ a : "string" }));
          assert.commandWorked(coll.insert({ a : "123" }));
          assert.commandWorked(coll.insert({ a: [ "string in array" ] }));
          assert.commandWorked(coll.insert({ a: [ { "foo": "string in object in array"} ] }));
          print("coll after inserts: " + tojson(coll.find().toArray()));
          assert.eq(8, coll.count());
      
          assert.commandWorked(db.runCommand({ delete: "coll", ordered: true, deletes: [ { q: { a: { "$gte": { "x.x": 100 }}}, limit: 0 }] }));
          print("coll after remove " + tojson(coll.find().toArray()));
          assert.eq(8, coll.count()); // expect fail 
      Show
      var mongod = MongoRunner.runMongod(); let db = mongod.getDB( "test" ); let coll = db.getCollection( "coll" ); assert .commandWorked(coll.insert({ a: { "y" : 1 }})); assert .commandWorked(coll.insert({ a: { "y" : 2 }})); assert .commandWorked(coll.insert({ a: { "x" : 1 }})); assert .commandWorked(coll.insert({ a: { "x" : 2 }})); assert .commandWorked(coll.insert({ a : "string" })); assert .commandWorked(coll.insert({ a : "123" })); assert .commandWorked(coll.insert({ a: [ "string in array" ] })); assert .commandWorked(coll.insert({ a: [ { "foo" : "string in object in array" } ] })); print( "coll after inserts: " + tojson(coll.find().toArray())); assert .eq(8, coll.count()); assert .commandWorked(db.runCommand({ delete: "coll" , ordered: true , deletes: [ { q: { a: { "$gte" : { "x.x" : 100 }}}, limit: 0 }] })); print( "coll after remove " + tojson(coll.find().toArray())); assert .eq(8, coll.count()); // expect fail

      Using $gte or $lt with an object value

      deletes: [ { q: { a: { "$gte": { "x.x": 100 }}}, limit: 0 }]

      seems to delete all documents where "a" is a document or array of documents (see repro script).

      Is this expected behavior?

            Assignee:
            asya.kamsky@mongodb.com Asya Kamsky
            Reporter:
            esha.maharishi@mongodb.com Esha Maharishi (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            9 Start watching this issue

              Created:
              Updated:
              Resolved: