Advertisement

MongoDB连接数据库

阅读量:

开启数据库 和 关闭数据库

复制代码
    net start mongodb
    net stop mongodb

2.连接数据库,如果没有这个名字的数据库,会自动创建

复制代码
    // 引入mongoose第三方模块 用来操作数据库
    const mongoose = require('mongoose');
    // 数据库连接
    mongoose.connect('mongodb://localhost/playground', { useNewUrlParser: true})
    	// 连接成功
    	.then(() => console.log('数据库连接成功'))
    	// 连接失败
    	.catch(err => console.log(err, '数据库连接失败'));

全部评论 (0)

还没有任何评论哟~