mongoose.model创建集合
来源:互联网 发布:oracle数据库分页查询 编辑:程序博客网 时间:2024/05/21 19:34
1. module.exports = mongoose.model(‘DepotLoc’, schema);
mongoose是通过model来创建mongodb中对应的集合(collection)
DepotLoc不会出现在数据库中,在数据库中会将集合描述小写,并且如果这个集合名尾巴没有s,数据库内部处理,会形成depotLocs集合
代码如下:
var mongoose = require('mongoose');var Device = require('./device');var uuid = require('uuid');var Schema = mongoose.Schema;var now = function () { return new Date();};// Exportsvar schema = new Schema({ group: { type: String, required: true, index: true }, location: { type: String, required: true, index: true }, depotid: { type: String, required: true, index: true }, deviceid: { type: Schema.Types.ObjectId, ref: "Device" }, prince: { type: Number }, volume: { type: Number }, img: { type: String }, isvacant: { type: Boolean }, apikey: { type: String, unique: true, default: uuid.v4 }, createdAt: { type: Date, index: true, default: now }});schema.static('', function(){});module.exports = mongoose.model('DepotLoc', schema);
2. 使用robo3T可视化本地数据库,你可以看到数据库结构,
确实新建了一个depotLocs集合
阅读全文
0 0
- mongoose.model创建集合
- mongoose删除集合方法
- mongoose集合命名的实例
- mongoose
- mongoose
- Mongoose
- Mongoose
- mongoose
- mongoose
- mongoose
- Mongoose
- mongoose
- Mongoose
- mongoose
- mongoose
- mongoose
- mongoose
- mongoose
- Ubuntu 设置默认root模式登录
- ISBN码
- 爬虫模拟登录知乎
- CNN学习(一)
- reduce端join算法实现
- mongoose.model创建集合
- 大型网站架构总结
- Activity的启动流程
- Java线程Thread
- Backpropagation Algorithm
- 【树状数组--思维】poj 3928 pingpong
- 快速好写的求最长回文子串的代码(O(n^2))
- 更改Mysql数据库存储位置的具体步骤
- Docker部署迁移实战