node.js - how to define mongoose schema for given collection? -
{ "_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" } } } }
so short version,there lots of dates , time slots.i want define schema in mongoose can query db.how should schema confused how generalize each date. , in defined schema how write query change avalabilty of specific date if specific time slot?
just 1 possible solution of thousend..
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} })
Comments
Post a Comment