我正在使用Rails 5.2.0,Ruby 2.5.0和MongoId 7.1.0,
一切都运行正常,但我使用此代码来获取有关集合大小的信息。但现在它失败了,错误:
Mongo::Error::OperationFailure (not authorized on[mydb] to execute command { $eval: "
var collectionNames = db.getCollectionNames(), stats = [];
collectionNames.forEach(function (n) { stats.push(db[n].stats()); });
stats = ...", args: [], nolock: true, $db: "super_control_development", $readPreference: { mode: "primary" } } (13)):
代码是:
db ||= Mongoid.default_client.database
# db = Mongoid::Config.clients[:default][:database]
f = """
var collectionNames = db.getCollectionNames(), stats = [];
collectionNames.forEach(function (n) { stats.push(db[n].stats()); });
stats = stats.sort(function(a, b) { return b['size'] - a['size']; });
return stats;
"""
result = db.command({:$eval => f, args: [], nolock: true})
@result_data = result.first['retval']
任何身体帮助我?
更多信息:
{“database”=>“mydb”,“user”=>“owner”,“password”=>“mypass”,“auth_source”=>“super_control_development”,“platform”=> “mongoid-7.1.0”}
谢谢。