When I run the query using java driver in Micronuat application DEBU" /> When I run the query using java driver in Micronuat application DEBU" /> When I run the query using java driver in Micronuat application DEBU"/>

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

524 Views Asked by At

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

1

There are 1 best solutions below

9
geobreze On

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"}}}})