mongooseでDeprecationWarning出たときの対応

mongo db使うときに次のようなエラー文が出力されるときがあります。
(node:16237) DeprecationWarning: current URL string parser is deprecated, and will be removed in a future version. To use the new parser, pass option { useNewUrlParser: true } to MongoClient.connect.
(node:16237) DeprecationWarning: current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to the MongoClient constructor.
そのような場合は、次のように指定するとよいです。

const express = require('express');
const mongoose = require('mongoose');
mongoose.connect(
    'mongodb+srv://(省略).mongodb.net/:(省略)', 
    { useNewUrlParser: true, useUnifiedTopology: true }
);

コメントを残す

*