数据库
1. 创建集合

const courseSchema = new mongoose.Schema({
name:String,
author: String,
isPublised: Boolean
});
//使用规则创建集合
const Course = mongoose.model('Course',courseSchema) //course
2. 创建文档

//引入mongoose第三方模块 用来操作数据库
const mongoose = require('mongoose');
//数据库连接
mongoose.connect('mongodb://localhost/playground', { useNewUrlParser: true})
.then(() => console.log('连接成功'))
.catch(err => console.log(err,'连接失败'));
//创建集合规则
const courseSchema = new mongoose.Schema({
name:String,
author: String,
isPublised: Boolean
});
//使用规则创建集合
const Course = mongoose.model('Course',courseSchema) //course
const course = new Course({
name:'hhh',
author:'袁航',
isPublised:true
});
course.save();
create方法

//引入mongoose第三方模块 用来操作数据库
const mongoose = require('mongoose');
//数据库连接
mongoose.connect('mongodb://localhost/playground', { useNewUrlParser: true})
.then(() => console.log('连接成功'))
.catch(err => console.log(err,'连接失败'));
//创建集合规则
const courseSchema = new mongoose.Schema({
name:String,
author: String,
isPublised: Boolean
});
//使用规则创建集合
const Course = mongoose.model('Course',courseSchema) //course
Course.create({name:'123',author:'yh',isPublised: true},(err,result) =>{
console.log(err)
console.log(result)
})
3.导入数据


4.查询数据



5.删除文档

6. 更新文档


网友评论