[JAVA-2225] Is there a way to add $comment find methods Created: 15/Jun/16  Updated: 11/Sep/19  Resolved: 15/Jun/16

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

Type: Task Priority: Major - P3
Reporter: Stefan Siegl Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

Hello,

is there a way to add the $comment to the DbCollection.find() method. It would be very usefull to trace the queries over different log-file (application log and mongodblog). Or any other ways to achieve tracebility?

Br

Stefan

https://docs.mongodb.com/manual/reference/operator/meta/comment/



 Comments   
Comment by Stefan Siegl [ 16/Jun/16 ]

I have extract all the relevant Code in a little main. There it works with MongoCollection as well. Now I have to find out myself, where is the difference in our productive code. Thank you again, Jeff.

Comment by Stefan Siegl [ 16/Jun/16 ]

I have tried with DBCollection yet. There I can find an entry in the profile collection, but not with MongoCollection. I would not like to move to DBCollection, because we have moved all of our Daos to MongoCollection some time ago. Why is it not possible with MongoCollection?

Comment by Jeffrey Yemin [ 16/Jun/16 ]

Neither DBCollection nor MongoCollection is working for you?

Comment by Stefan Siegl [ 16/Jun/16 ]

Hi again,

actually it is impossible for me to get this stuff running.
I have set the profilingLevel on 2, to log all operations. In the system.profile I can find the query, but a comment is not added. If I use the mongoshell an type find.comment("HERE IT IS"), than I can find these comment in the profiling collection.

Perhaps you can give me another hint?

Br

Stefan

Comment by Stefan Siegl [ 15/Jun/16 ]

Thank you. That´s what I need. In my opinion the way with .comment is a little bit more intuitive, but I am glad that it is possible

Comment by Jeffrey Yemin [ 15/Jun/16 ]

It's a bit more obscure in MongoCollection:

MongoCollection<Document> coll = ...;
coll.find().modifiers(new Document("$comment", "<insert comment here"))

Comment by Stefan Siegl [ 15/Jun/16 ]

Is there also a method when I use MongoCollection?

As I understand right, your advice is to use MongoCollection instead of DBCollection?

http://stackoverflow.com/questions/29364787/mongocollection-versus-dbcollection-java

find() returns FindIterable. But I cannot find a method comment in FindIterable

Comment by Jeffrey Yemin [ 15/Jun/16 ]

There's a helper method on DBCursor:

DBCollection coll = ...;
coll.find().comment("<insert comment here>")

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