0
有沒有辦法以SQL的形式執行MongoDB查詢,類似於JDBC Statement。Java執行Mongodb原始查詢
例如我想執行查詢db.products.find({"_id" : ObjectId("56eadecd69eefd335e8d8f0d")}).pretty();
,因爲它使用Java。你能分享一些例子嗎?我想下面的代碼
BasicDBObject obj = new BasicDBObject();
obj.append("$eval", query);
CommandResult cr = mongoTemplate.executeCommand(obj);
String createdBy = cr.getString("createdBy");
但它返回錯誤
{ "serverUsed" : "xxxxx" , "ok" : 0.0 , "errmsg" : "not authorized on shopchatdb to execute command { $eval: \"db.products.find({\"_id\" : ObjectId(\"56eadecd69eefd335e8d8f0d\")}).pretty()\" }" , "code" : 13}