Node.js 如何为给定集合定义mongoose模式?
这只是一个简短的版本,会有很多日期和时间段。我想在mongoose中定义模式,这样我就可以查询数据库。模式应该是什么样的,因为我不知道如何概括每个日期。Node.js 如何为给定集合定义mongoose模式?,node.js,mongodb,mongoose,mongoose-schema,Node.js,Mongodb,Mongoose,Mongoose Schema,这只是一个简短的版本,会有很多日期和时间段。我想在mongoose中定义模式,这样我就可以查询数据库。模式应该是什么样的,因为我不知道如何概括每个日期。 此外,在已定义的模式中,我将如何编写查询以更改特定时间段中特定日期的可用性?这只是一个可能的解决方案 { "_id" : ObjectId("56b84dab9f973b3cd5f52c8c"), "userid" : "abcde", "dates" : { "2-01-2015" : {
此外,在已定义的模式中,我将如何编写查询以更改特定时间段中特定日期的可用性?这只是一个可能的解决方案
{
"_id" : ObjectId("56b84dab9f973b3cd5f52c8c"),
"userid" : "abcde",
"dates" : {
"2-01-2015" : {
"9-10" : {
"ava" : "no",
"bookibg_id" : "null"
},
"10-11" : {
"ava" : "no",
"bookibg_id" : "null"
}
},
"3-01-2015" : {
"9-10" : {
"ava" : "no",
"bookibg_id" : "null"
},
"10-11" : {
"ava" : "no",
"bookibg_id" : "null"
}
}
}
}
{
"_id" : ObjectId("56b84ed19f973b3cd5f52c8d"),
"userid" : "abcde",
"dates" : {
"2-01-2015" : {
"9-10" : {
"ava" : "no",
"bookibg_id" : "null"
},
"10-11" : {
"ava" : "no",
"bookibg_id" : "null"
}
},
"3-01-2015" : {
"9-10" : {
"ava" : "no",
"bookibg_id" : "null"
},
"10-11" : {
"ava" : "no",
"bookibg_id" : "null"
}
}
}
}
{
"_id" : ObjectId("56b84ed19f973b3cd5f52c8e"),
"userid" : "abcde",
"dates" : {
"2-01-2015" : {
"9-10" : {
"ava" : "no",
"bookibg_id" : "null"
},
"10-11" : {
"ava" : "no",
"bookibg_id" : "null"
}
},
"3-01-2015" : {
"9-10" : {
"ava" : "no",
"bookibg_id" : "null"
},
"10-11" : {
"ava" : "no",
"bookibg_id" : "null"
}
}
}
}
var XY = new mongoose.Schema({
userId: {type: String, required: true},
dates: [{type: String, ref: 'Date' }]
})
var Date = new mongoose.Schema({
timestamp: {type: Date, required: true},
timeSlots: [{type: String, ref: 'TimeSlot'}]
})
var TimeSlot = new mongoose.Schema({
startHour: {type: Number, required: true},
endHour: {type: Number, required: true},
ava: {type: String},
bookibg_id: {type: String}
})