Callback function never called after Mongoose query is executed

前端 未结 3 755
伪装坚强ぢ
伪装坚强ぢ 2021-02-14 14:25

The following is my code:

mongoose.connect(\'mongodb://localhost/mydatabase\');
  var db = mongoose.connection;
db.on(\'error\', console.error.bind(console, \'co         


        
3条回答
  •  醉梦人生
    2021-02-14 14:53

    Have you tried doing your query after the database connection opens? I don't have a Mongoose server to test it, but that would be my first guess.

    var Stuff = mongoose.model('Stuff', StuffSchema);
    
    db.once('open', function () {
      Stuff.find({}, function (e, body) {
        console.log('It worked!');
      });
    });
    

    Sorry, if this doesn't end up fixing it.

提交回复
热议问题