简体   繁体   中英

unable to connect mongodb database to localhost it showing not connected

mongoose.connect( DB, {useNewUrlParser: true, useCreateIndex: true, useUnifiedTopology: true, useFindAndModify:false }).then(() => { console.log( connection successful ); }).catch((err) =>console.log( no connection ));

It look like you are passing wrong dbURL your url should look like this

mongodb+srv://<username>:<password>@<cluster_name>.<dbid>.mongodb.net/<Database_Name>?retryWrites=true&w=majority

Try this

   const dbURL = Your mongoDb url
   mongoose.connect(dbURI, { useNewUrlParser: true, useUnifiedTopology: true })
  .then(result => console.log('connected to db'))
  .catch(err => console.log(err));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM