0

尝试了大约 3 个小时将 a 翻译db.collection('collection-name').find()为 mongoose,但似乎永远无法验证find().

堆栈跟踪:

Error: unauthorized db:parks ns:parks.parkpoints lock type:0 client:127.2.132.1
at Promise.error (/var/lib/user/app-root/runtime/repo/node_modules/mongoose/lib/promise.js:88:38)
at cb (/var/lib/user/app-root/runtime/repo/node_modules/mongoose/lib/query.js:1454:29)
at /var/lib/user/app-root/runtime/repo/node_modules/mongoose/lib/utils.js:408:16
at /var/lib/user/app-root/runtime/repo/node_modules/mongodb/lib/mongodb/cursor.js:146:30
at /var/lib/user/app-root/runtime/repo/node_modules/mongodb/lib/mongodb/cursor.js:188:32
at /var/lib/user/app-root/runtime/repo/node_modules/mongodb/lib/mongodb/cursor.js:504:39
at Cursor.close (/var/lib/user/app-root/runtime/repo/node_modules/mongodb/lib/mongodb/cursor.js:776:5)
at [object Object].<anonymous> (/var/lib/user/app-root/runtime/repo/node_modules/mongodb/lib/mongodb/cursor.js:504:21)
at [object Object].g (events.js:156:14)
at [object Object].emit (events.js:88:20)
npm info Sample-App@1.0.0 Failed to exec start script

Connection.once('open')事件被命中,所以连接不应该是问题,但我一直在console.log("find() error");.

有人知道发生了什么吗?

  • 数据库名称:公园
  • 集合名称:parkpoints
  • 猫鼬版本:3.3.1
  • MongoDB版本:2.2.0

我仔细检查了用户、通行证、主机和端口的值,这些不应该是问题的根源。

self.connectDb = function(callback){
mongoose.connection.on('error', function(err){
  console.log("connection error");
  throw err;});
mongoose.connection.once('open', function(){
  callback();
  self.Parkpoint=mongoose.connection.model('Parkpoint', 
           new Schema({ Name: String, pos: [Number]})); 

  self.Parkpoint.find().exec(function(err, names) {
    if(err){
      console.log("find() error");
      throw err};
     console.log("names: "+names);
    res.header("Content-Type:","application/json");
    res.end(JSON.stringify(names));
});


});

var dbUri = 'mongodb://'+self.dbUser+':'+self.dbPass+'@'+self.dbHost+':'+self.dbPort+'/parks';
console.log(dbUri);
mongoose.connect(self.dbHost, "parks", self.dbPort, {user:self.dbUser, pass:self.dbPass});
};
4

1 回答 1

0

已解决:需要运行 addUser() 命令为数据库添加身份验证。我认为它工作,因为 mongodb 驱动程序工作,但显然该用户从未真正添加......也许是因为它是管理员。根本原因仍然不是很清楚,但问题似乎很容易解决,更多地关注身份验证管理。

于 2012-11-07T23:26:57.413 回答