mongoDB 中的弃用错误,我应该在哪里传递参数?

Deprecation errors in mongoDB, where should I pass the parameters?

我正在使用 mongoDB 存储 2 个文件,我收到了这些消息:

弃用警告: 当前的 URL 字符串解析器已弃用,并将在未来版本中删除。要使用新的解析器,请将选项 { useNewUrlParser: true } 传递给 MongoClient.connect.

弃用警告: 当前的服务器发现和监控引擎已弃用,并将在未来版本中删除。要使用新的服务器发现和监控引擎,请将选项 { useUnifiedTopology: true } 传递给 MongoClient 构造函数。

这是我的代码,我不知道应该将这些选项传递给哪里:

var storageImage = new GridFsStorage({
  url: dbURI,
  file: (req, file) => {
    return new Promise((resolve, reject) => {
      crypto.randomBytes(16, (err, buf) => {
        if (err) {
          return reject(err);
        }
        const filename = buf.toString("hex") + path.extname(file.originalname);
        const fileInfo = {
          filename: filename,
          bucketName: "user_images"
        };
        resolve(fileInfo);
      });
    });
  }
});
const uploadImage = multer({ storage: storageImage });

var storageDoc = new GridFsStorage({
  url: dbURI,
  file: (req, file) => {
    return new Promise((resolve, reject) => {
      crypto.randomBytes(16, (err, buf) => {
        if (err) {
          return reject(err);
        }
        const filename = buf.toString("hex") + path.extname(file.originalname);
        const fileInfo = {
          filename: filename,
          bucketName: "user_cv"
        };
        resolve(fileInfo);
      });
    });
  }
});
const uploadDoc = multer({ storage: storageDoc });

//routes

router.post("/uploadImage", uploadImage.single("file"), (req, res) => {
  console.log(req.file);
  res.json({ imageId: req.file.id });
});

router.post("/uploadCV", uploadDoc.single("file"), (req, res) => {
  console.log(req.file);
  res.json({ cvId: req.file.id });
});

module.exports = router;

这样试试。添加此行应该有效 options: { useNewUrlParser: true }.

new GridFsStorage({
  url: dbURI,
  options: { useNewUrlParser: true },
  ...,
});