[SERVER-84702] $project fails to exclude duplicated keys Created: 09/Jan/24  Updated: 29/Jan/24

Status: Investigating
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Evan Darke Assignee: Edwin Zhou
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Operating System: ALL
Participants:

 Description   

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

 


Generated at Thu Feb 08 06:55:44 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.