Mongoose .find() method causes requests to hang

后端 未结 1 1669
渐次进展
渐次进展 2020-11-27 08:16

I have this route defined, but any requests made to it get\'s stuck on \'pending\' and runs forever.

When I log the code, I see 1 followed by 4

相关标签:
1条回答
  • 2020-11-27 08:58

    Until you call mongoose.connect, your mongoose queries will simply be queued up.

    Add code like this in your startup code to connect:

    mongoose.connect('mongodb://localhost/test', function(err) {
        if (err) {
            console.err(err);
        } else {
            console.log('Connected');
        }    
    });
    

    In the connection string, replace test with the name of your database.

    0 讨论(0)
提交回复
热议问题