5
6

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.

mongoose.connect()時のエラー

Posted at

node.jsのmongoose.connect()時のエラー

エラー内容

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

Google翻訳で翻訳
DeprecationWarning:現在のURL文字列パーサは廃止され、将来のバージョンで削除されます。 新しいパーサを使用するには、オプション{useNewUrlParser:true}をMongoClient.connectに渡します。

あとこちらの記事「MongoClient.connect()時にuseNewUrlParserオプションを与える」も参考にし、第二引数に{ useNewUrlParser: true }を追加するとエラーが消えた。

node.js
const express = require('express');
const mongoose = require('mongoose');

mongoose.connect('mongodb://(省略).mlab.com:(省略)', { useNewUrlParser: true });

const app = express();

app.get('/rentals', function(req, res) {
  res.json({'success': true});
});

const PORT = process.env.PORT || 3001;

app.listen(PORT, function() {
  console.log('I am runnnig');
});

とても助かりました。

参考記事

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

5
6
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
5
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?