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();
};
// Exports
var 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集合