连接到 mongoDB [英] connection to mongoDB
本文介绍了连接到 mongoDB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是 nodeJS 和 mongodb 的新手.我无法将我的代码与 mongodb 连接.这是我的代码.当我运行这段代码时,它给了我这个,
I am a new in nodeJS and mongodb. I can not connect my code with mongodb. here is my code. when I run this code it gives me this,
(node:9160) DeprecationWarning: 当前 URL 字符串解析器是已弃用,并将在未来版本中删除.要使用新解析器,将选项 { useNewUrlParser: true }
传递给 MongoClient.connect
.
(node:9160) DeprecationWarning: current URL string parser is deprecated, and will be removed in a future version. To use the new parser, pass option
{ useNewUrlParser: true }
toMongoClient.connect
.
我该如何解决?
var express = require("express");
var mongoose = require("mongoose");
var passport = require("passport");
var bodyParser = require("body-parser");
var LocalStrategy = require("passport-local");
var passportLocalMongoose = require("passport-local-mongoose");
mongoose.connect("mongodb://localhost/mydb");
// mongoose.connect("mongodb://localhost:27017/mydb_login", { useNewUrlParser: true })
var app = express();
app.set("view engine", "ejs");
推荐答案
试试吧,我想它会对你有所帮助.
Try it, I think it will help you.
let MONGOOSE = require('mongoose');
MONGOOSE.connect('mongodb://127.0.0.1:27017/demo', (err, response)=>{
if(err)
reject(err);
else
resolve(null);
});
这篇关于连接到 mongoDB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文