mongoose 与 mylab 的使用 (1)

1.引入mongoose  模块

const  mongoose =   require('mongoose');

  

2.连接数据库

//连接数据库
mongoose.connect(
     db,
     {useNewUrlParser:true}
).then(()=>{
     console.log('数据库连接成功');
}).catch((err)=>{
      throw(err);
})

  3.引入db  配置文件

//引进文件
const  db= require('./config/key').openUri;

  

4.key.js

module.exports={
    openUri:"mongodb://test:[email protected]:33094/koa-restful-api",
    secretOrKey:'secret'
}
mongodb://test:[email protected]:33094/koa-restful-api  这个是你的mLab 地址
test  是mLab用户名
test123456  是 mLab  的密码


猜你喜欢

转载自www.cnblogs.com/guangzhou11/p/10356257.html