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

$project fails to exclude duplicated keys

    • Type: Icon: Bug Bug
    • Resolution: Community Answered
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • ALL

      When inserting a RawBsonDocument that includes duplicated keys, and attempting to exclude said key in a `$project` stage, only the first occurrence of the key is excluded. This appears to be a probable bug.

       

      Tested in the Java driver because the shell doesn't support duplicate keys:

      MongoClient client = MongoClients.create("mongodb://mongoUser:hunter1@localhost:37017/?authSource=admin");
      RawBsonDocument doc = RawBsonDocument.parse("{a: 5, a: 6, a: 7}");
      
      client.getDatabase("keys").getCollection("fts", RawBsonDocument.class).insertOne(doc);
      
      var v = client.getDatabase("keys").getCollection("fts", RawBsonDocument.class)
          .aggregate(List.of(new BsonDocument("$project", new BsonDocument("a", new BsonInt64(0)))));
      System.out.println(v.iterator().tryNext()); 

       

      Results in the output:

      {"_id": {"$oid": "659daa98f2c70319473b5206"}, "a": 6, "a": 7}
      

       

      Or the logically equivalent shell syntax:

      keys> db.fts.insert({a: 5, a: 6, a: 7}) # Not supported in shell
      keys> db.fts.aggregate({$project: {a: 0}}) 
      [ { _id: ObjectId("659daa98f2c70319473b5206"), a: 6, a: 7 } ]

       

       

      Tested in version:  7.2.0-rc1

      Tested with non-covered $project

       

            Assignee:
            edwin.zhou@mongodb.com Edwin Zhou
            Reporter:
            evan.darke@mongodb.com Evan Darke
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: