Mohammed Gadiwala February 2016

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 this is just a short version,there will be lots of dates and time slots.I want to define schema in mongoose so that i can query the db.How should the schema be as i am confused how to gener

Answers


Sprotte February 2016

Just one 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}
 })

Post Status

Asked in February 2016
Viewed 2,929 times
Voted 6
Answered 1 times

Search




Leave an answer