[英]not connect with default port on mongo db using Nodejs
i am new in node js and i try to connect with mongodb with node js app but i am not able to connect Here is my code我是 node js 的新手,我尝试使用 node js 应用程序与 mongodb 连接,但我无法连接这是我的代码
var mongo = require("mongodb"); var host="127.0.0.1"; //var port="27017"; var port=mongo.Connection.DEFAULT_PORT; var db=new mongo.Db("nodejs-intoduction",new mongo.Server(host, port,{})); db.open(function(error){ console.log("We are connected.!" + host + ":" + port); })
i am getting error like..我收到错误,例如..
port=mongo.Connection.DEFAULT_PORT;端口 = mongo.Connection.DEFAULT_PORT;
cannote read property 'DEFAULT_POST' of undefined无法读取未定义的属性“DEFAULT_POST”
use this code使用此代码
var MongoClient = require('mongodb').MongoClient,
// Connection url
var url = 'mongodb://localhost:27017/test';
// Connect using MongoClient
MongoClient.connect(url, function(err, db) {
db.close();
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.