使用Atlas连接到数据库(mongoDB)时,如何使Express Server侦听指定的端口?

我想使Express Server在连接到数据库时侦听指定的端口,但是我正在使用Atlas MongoDB,我有一个解决方案,但这意味着在本地安装mongoDB,我不想这样做。我发现Atlas更加方便。所以我得到了这段代码:

let db;

mongoose.connect(mongoSRV,{ useNewUrlParser: true,useUnifiedTopology: true,},(err,client) => {
    if (err) return console.log(err);

    db = client.db('StarWars');
    app.listen(3000,() => console.log('listening on 3000'));
});

为了得到错误TypeError: client.db is not a function

我希望能够仅使用Atlas而无需在计算机上安装mongo就能实现相同的概念。

i530151196 回答:使用Atlas连接到数据库(mongoDB)时,如何使Express Server侦听指定的端口?

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3090931.html

大家都在问