简体   繁体   中英

How can I log actual queries to MongoDB with mongo java driver in Micronaut application

I am setting the mongo logger as below

<logger name="org.mongodb" level="debug"/>

When I run the query using java driver in Micronuat application

DEBUG org.mongodb.driver.protocol.command - Sending command '{"aggregate": "product.category", "pipeline": [{"$match": {"$and": [{"_id": {"$oid": "60c4aed3afb396342bf90802"}}, {"subCategory._id": {"$oid": "60cc5dd52b5cf415ded7de5d"}}]}}, {"$group": {"_id": 1, "n": {"$sum": 1}}}], "cursor": {}, "$db": "FeteBird-Product", "lsid": {"id": {"$binary": {"base64": "9UGXhsvnSZ+FXRCDwsiyWA==", "subType": "04"}}}}'

But if I copy this command and try to run in mongoshell it won't work, how can I show what exact query it is generating. So that I can run that query and see the output on console

Try running your command using runCommand

mongo shell> use database_name
mongo shell> db.runCommand({"aggregate": "product.category", "pipeline": [{"$match": {"$and": [{"_id": {"$oid": "60c4aed3afb396342bf90802"}}, {"subCategory._id": {"$oid": "60cc5dd52b5cf415ded7de5d"}}]}}, {"$group": {"_id": 1, "n": {"$sum": 1}}}], "cursor": {}, "$db": "FeteBird-Product", "lsid": {"id": {"$binary": {"base64": "9UGXhsvnSZ+FXRCDwsiyWA==", "subType": "04"}}}})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM