[JAVA-2213] Missing filter criteria on CommandStartedEvent when run old DB versions <3.2 Created: 09/Jun/16  Updated: 03/Oct/16  Resolved: 03/Oct/16

Status: Closed
Project: Java Driver
Component/s: Monitoring
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Minor - P4
Reporter: Stephen Dalby Assignee: Unassigned
Resolution: Won't Fix Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: Java Source File DriverTest.java    

 Description   

When the following code is executed against a version of the database earlier than 3.2 where a CommandListener has been configured, the filter criteria is omitted from the CommandStartedEvent when a $comment has been manually added to the query:

MongoClient mongoClient = new MongoClient("localhost", options);
MongoDatabase test = mongoClient.getDatabase("test");
MongoCollection<Document> coll = test.getCollection("TestCollection");
 
coll.insertOne(new Document("a", 1));
coll.find(new Document("a", 1)).modifiers(new Document("$comment", "test")).first();
coll.find(new Document("a", 1).append("$comment", "test")).first();

Against 3.2, the following output is seen:

{ "insert" : "TestCollection", "ordered" : true, "documents" : [{ "_id" : { "$oid" : "57594e2ce97b981da4837eb1" }, "a" : 1 }] }
{ "find" : "TestCollection", "comment" : "test", "filter" : { "a" : 1 }, "limit" : 1, "singleBatch" : true }
{ "find" : "TestCollection", "filter" : { "a" : 1, "$comment" : "test" }, "limit" : 1, "singleBatch" : true }

Against 2.6 or 3.0, the output is:

{ "insert" : "TestCollection", "ordered" : true, "documents" : [{ "_id" : { "$oid" : "57595531e97b981dd04c719b" }, "a" : 1 }] }
{ "find" : "TestCollection", "comment" : "test", "filter" : { "a" : 1 }, "limit" : -1 }
{ "find" : "TestCollection", "comment" : "test", "limit" : -1 }

A source file is attached which when compiled reliable reproduces the issue.

This was tested against version 3.2.2 of the driver.



 Comments   
Comment by Jeffrey Yemin [ 03/Oct/16 ]

Closing as Won't Fix, as there are multiple workarounds to the observed behavior, by specifying $comment with modifiers or by specifying the filter with $query,

Comment by Jeffrey Yemin [ 09/Jun/16 ]

This also works as expected:

coll.find(new Document("$query", new Document("a", 1)).append("$comment", "test"))

Comment by Jeffrey Yemin [ 09/Jun/16 ]

Thanks for the bug report. I see what the problem is. If you use the modifiers method for the $comment instead of including it directly in the filter, it works as expected:

coll.find(new Document("a", 1)).modifiers(new Document("$comment", "test"))

Generated at Thu Feb 08 08:56:37 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.