mongodb和mongoose连接数据库


npm install mongodb
var MongoClient = require('mongodb').MongoClient;
var url = "mongodb://7.7.1.188:27017/ycdl";
 
MongoClient.connect(url, {useUnifiedTopology:true},{ useNewUrlParser: true }, function(err, db) {
  if (err) throw err;
  console.log("数据库已创建!");
  db.close();
});

npm install mongoose
var mongoose = require('mongoose'),
url = 'mongodb://7.7.1.188:27017/ycdl';

mongoose.connect('mongodb://7.7.1.188:27017/ycdl', { useNewUrlParser: true, useUnifiedTopology: true });
mongoose.connection.once('open',() => {
  console.log('conncetion is ok.')
});

评论

© 2021 成都云创动力科技有限公司 蜀ICP备20006351号-1