我想在mongodb中为每个集合使用多个模式,如何使用它?
当我尝试运行它时,它给我这个错误:
错误:
当我尝试运行它时,它给我这个错误:
错误:
OverwriteModelError: Cannot overwrite
allUsers
model once compiled.
OverwriteModelError: Cannot overwritecheckInOut
model once compiled.
爱我的schema.js
var mongoose = require('mongoose'); var Schema = mongoose.Schema,ObjectId = Schema.ObjectId; var checkInInfoSchema= new Schema({ name:String,loginSerialId:Number }); var loginUserSchema = new Schema({ sn : { type: Number,unique:true },uname: {type:String,unique:true},pass:String }); var registerUserSchema = new Schema({ sn : { type: Number,name: String //his/her name,pass:String,companyKey:{type:String},uname:{type:String,unique:true} }); var checkInOutSchema = new Schema({ uname: String,companyKey:String,task:String,inTime:String,outTime:String,date:{type:String},serialId:{type:Number,online:Boolean }); //Different schema for same collection "allUsers" var allUser=mongoose.model('allUsers',loginUserSchema); var registerUser=mongoose.model('allUsers',registerUserSchema); //Different schema for same collection "checkInOut" var checkInOut=mongoose.model('checkInOut',checkInOutSchema); var checkInInfo=mongoose.model('checkInOut',checkInInfoSchema); module.exports={ allUser:allUser,registerUser:registerUser,checkInOut:checkInOut,checkInInfo:checkInInfo };
解决方法
在猫鼬你可以做这样的事情:
var users = mongoose.model('User',loginUserSchema,'users'); var registerUser = mongoose.model('Registered',registerUserSchema,'users');
这两个模式将保存在“用户”集合上.
有关更多信息,请参阅文档:http://mongoosejs.com/docs/api.html#index_Mongoose-model或您可以看到以下gist可能有帮助.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。