24
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

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/

24
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
24
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?