Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 577 Vote(s) - 3.52 Average
  • 1
  • 2
  • 3
  • 4
  • 5
MongoDB mongoose Deprecation Warning

#11
mongoose.connect(process.env.DATABASE, {
useNewUrlParser: true,
useCreateIndex: true,
useFindAndModify: false,
useUnifiedTopology: true,
})
.then(() => {
console.log("DB connected");
})
.catch((err) => console.log(`DB connection Err`, err));
Reply

#12
here
`connectionString` is your DB Address
```javascript
mongoose
.connect(connectionString, {
useNewUrlParser: true,
useUnifiedTopology: true,
useCreateIndex: true,
})
.then(
app.listen(port, () => {
console.log(`server started on port ${port}`);
})
)
.catch((err) => console.log(err));
```
Reply

#13
When we make connection request to connect mongo db we just have to add one more key value pair into that callback function

useCreateIndex:true

inside the function

mongoose.connect(config.DB_URI, {
useNewUrlParser: true,
useUnifiedTopology: true,
useCreateIndex:true
}
Reply

#14
**Am using mongoose version 6.8.0 and this worked for me**

```
//connect mongodb
mongoose.set('strictQuery', false);
mongoose.connect('url',(err,db) => {

if(err){
console.log(`Database not connected : ${err}`)
}else{
console.log('Database connected Successfully')
}
})
```
Reply

#15
if depreciation error occurred to you while trying to connect to your mongodb database, if you are storing your connection strings in an environment variables file, like this

//database connection string saved to a env variable
DB='mongodb://127.0.0.1:27017/players'

use the actual ip address instead of the common way of defining it:

DB='mongodb://localhost/players'

Then, when connecting to the database you can use, this code:

//requiring the database driver mongoose
const mongoose = require('mongoose');

//connecting to mongodb
mongoose.connect(process.env.DB)
.then(() => console.log('Connected to mongodb Database...'))
.catch((err) => console.error('Unable to connect to MongoDB...', err));

This definitely, worked for me..am using locally on my machine so if you are using server based database then your database connnection string will not be the same as mine.
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through