23
8

More than 5 years have passed since last update.

MongoClient.connect()時にuseNewUrlParserオプションを与える

Posted at

Node.jsでMongoDBの接続を得るときにこんなエラーが出たときの対処法メモ。

(node:2368) 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.

エラーメッセージに従い、{useNewUrlParser: true}を第二引数に与える。

async connect() {
  if(this.conn) {
    return this.conn;
  } else {
    this.client = await MongoClient.connect(this.url, {useNewUrlParser: true});
    this.conn = this.client.db();
    return this.conn;
  }
}

同じこと書いてる人が海外にいた。
https://www.thanhphu.tech/2018/05/23/about-mongos-usenewurlparser-warning/

23
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
23
8