Fail to connect Mongoose to Atlas

后端 未结 3 1323
抹茶落季
抹茶落季 2020-12-01 09:52

I\'m always connecting to the \"admin\" DB, which is a fixed bug.

Using Mongoose 5.0.6 MongoDb 3.6 and trying to connect to Atlas.

  1. My question, what dr
3条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-01 10:06

    Basically you should try connecting with your url link, and specify the DB name on the mongoose connect method so if your cluster link is:

    mongodb+srv://userName:Passwrod@clustor.mongodb.net/
    

    and your DB name is:

    testDB
    

    then you should call the mongoose.connect method as follows:

    mongoose.connect('mongodb+srv://userName:Passwrod@cluster.mongodb.net/', {dbName: 'testDB'});
    

提交回复
热议问题