- schema创建一张表的数据结构
~~~
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
//mixed可以存储任何类型的数据
const {ObjectId,Mixed} = Schema.Types.Mixed;
const movieSchema = new Schema({
doubanId:{
unique:true,
type:String
},
category:[{
type:ObjectId,
ref:'Movie'
}],
rate:Number,
title:String,
summary:String,
video:String,
poster:String,
cover:String,
rawTitle:String,
movieTypes:[String],
pubdate:Mixed,
year:Number,
tags:Array,
meta:{
createdAt:{
type:Date,
default:Date.now()
},
updatedAt:{
type:Date,
default:Date.now()
}
}
})
mongoose.model('Movie',movieSchema)
~~~
- model
利用model函数发布这张表
- 第一章 入门
- 1-1 项目技术栈
- 1-1 promise
- 1-1-1 promise-ajax
- 1-1-1 util.promisify
- 1-2 async
- 1-2-1 async-await
- 1-2-2 async-util.promisify
- 1-3 async-map
- 1-3 iterator
- 1-4 generator
- 1-4-1 generator基础
- 1-4-2 generator-ajax
- 1-5 process
- 1-0 参考教程
- 1-6 静态方法
- 1-7 单例
- 第二章 ES-7
- 2-1 co
- 2-2 异步读取文件
- 2-3 co-ajax
- 第三章 koa核心
- 3-1 server
- 3-2 koa的中间件
- 3-3 koa-session
- 3-3 koa-router
- 3-3-1 ctx.params动态路由
- 3-4 koa路由get传值
- 3-5 中间件
- 3-5-1匹配路由之前设置一个中间件
- 3-5-2 中间件执行顺序
- 3-5-3 错误处理中间件
- 3-6 ejs
- 3-6-1 ejs基本语法
- 3-7 koa-post
- 3-8 koa-static静态资源中间件
- 3-9 art-template
- 3-10 koa-cookie的使用
- 3-11 koa-session
- 3-12 koa应用生产器
- 第四章
- 第一节 pug模板
- 第二节 puppeteer爬虫
- 2-1 爬取豆瓣top250数据
- 2-2 爬取豆瓣剧情页数据
- 第三节 将数据上传到七牛
- 第五章 mongoBD
- 5-1 安装
- 5-2 基本命令
- 5-3 mongoose连接数据库
- 5-3-1 简单连接数据库
- 5-3-2 schema,model,entity
- 5-3-3 schema向数据库中添加数据
- 5-3-4 豆瓣数据添加到数据库
- 5-3-5 glob引入schema
- 5-3-6 schema的数据类型
- 5-4 从数据库取得数据返回给前台
- 5-5 mongo数据库取数据生成接口