Hello I have issue with MongoDB code, it make some methods like this (image below):
enter image description here
`
var MongoClient = require('mongodb').MongoClient;
var url = "mongodb://localhost:27017/";
MongoClient.connect(url, { useUnifiedTopology: true }, function (err, db) {
if (err) throw err;
var dbo = db.db("mydb");
var mysort = { name: 1 };
dbo.collection("customers").find().sort(mysort).toArray(function (err, result) {
if (err) throw err;
console.log(result);
db.close();
});
});
`
and when I try read error, it say:
(method) MongoClient.connect(url: string, callback: Callback): void (+3 overloads)
@deprecated — Callbacks are deprecated and will be removed in the next major version. See mongodb-legacy for migration assistance
The signature ‘(url: string, callback: Callback): void’ of ‘MongoClient.connect’ is deprecated.ts(6387)
mongodb.d.ts(4733, 9): The declaration was marked as deprecated here.
No quick fixes available
I tried reinstall it, or install older version and still same, I do connection same like in documentation.
Tried add (url,{ useUnifiedTopology: true }, and still same
Someone know what can be issue?
2
Answers
Try version 4.0.0
Let me know if you still have the same error .
Step 1: Replace your current version with the following:
Step 2: Require this into your project