标签:col 编译 erro count lang 工具 val 数据 view
Schema: 模式,在模式里面我们对数据进行定义,定义字段对类型,比如是字符串类型,还是数字类型
Model: 模型,编译模型,对传入对Schema进行编译,然后会生成构造函数
Documents: 文档
var mongoose = require(‘mogoose‘); var MovieSchema = new mongoose.Schema({ doctor:String, title:String, language:String, country:String, year:Number, summary:String })
var mongoose = require(‘mongoose‘); var MovieSchema = require(‘./schemas/movie‘); var Movie = mongoose.model(‘Movie‘,MovieSchema) module.exports = Movie
//Documents-文档实例化 var Movie = require(‘./model/movie‘); var movie = new Movie({ title:‘机械战警‘, doctor:‘何塞.帕迪利亚‘, year:2018 }) movie.save(function(err){ if(err){ return handleError(err); } })
//Documents - 数据库批量查询 var Movie = require(‘./models/movie‘); app.get(‘/‘,function(req,res){ Movie .find({}) .exec(function(err,movies){ res.render(‘index‘,{ title:‘imooc首页‘, movies:movies }) }) })
//Documents - 数据库单条查询 var Movie = require(‘./models/movie‘); app.get(‘/‘,function(req,res){ Movie .findOne({_id:id}) .exec(function(err,movies){ res.render(‘index‘,{ title:‘imooc首页‘, movies:movies }) }) })
//Documents - 数据库单条删除 var Movie = require(‘./models/movie‘); app.get(‘/‘,function(req,res){ Movie .remove({_id:id},function(err,movie){ if(err){ console.log(err); } }) })
nodeMongodb
node_modules
bower_components
view
index.jade
detail.jade
admin.jade
list.jade
models
movie.js
schemas
movie.js
app.js
标签:col 编译 erro count lang 工具 val 数据 view
原文地址:https://www.cnblogs.com/wzndkj/p/9339497.html