我正在开发一个Web应用程序来通过java驱动程序运行本机mongo查询,这样我就可以在良好的UI中看到结果。我没有找到直接的方法,但运行js函数似乎是一种方法。
我可以从mongo shell运行以下脚本,
rs1:PRIMARY> function showShortedItems() { return db.Items.find({});}
rs1:PRIMARY> showShortedItems()
But while trying same thing from java driver,nope。
val db = connection.getDatabase(Database.Name)
val command = new BasicDBObject("eval", "function() { return db.Items.find(); }")
val result = db.runCommand(command)
我得到的错误是,
Caused by: com.mongodb.MongoCommandException: Command failed with error 13: 'not authorized on shipping-db to execute command { eval: "function() { return db.Items.find(); }" }' on server localhost:27017.
The full response is { "ok" : 0.0, "errmsg" : "not authorized on shipping-db to execute command { eval: \"function() { return db.Items.find(); }\" }", "code" : 13 }
rs1:PRIMARY> db.system.users.find({})
为空。
mongo.conf
storage:
journal:
enabled: false