问题描述
我正在如下设置 mongo 记录器
<logger name="org.mongodb" level="debug"/>
当我在 Micronuat 应用程序中使用 java 驱动程序运行查询时
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"}}}}'
但是,如果我复制此命令并尝试在 mongoshell 中运行,它将无法正常工作,我如何才能显示它生成的确切查询。这样我就可以运行该查询并在控制台上查看输出
解决方法
尝试使用 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"}}}})