buunguyen / mongoose-deep-populate

Mongoose plugin to enable deep population of nested models ⛺
MIT License
469 stars 44 forks source link

How to use the deep populate #37

Closed EliArad closed 8 years ago

EliArad commented 8 years ago

Hi , is this the right place to ask questions?

I have some big schema , i will not write then all , try to short then and get to the question. i know how one level of populate is working, but what i need to do , i think is a deep populate or nested , i dont know

first schema: var CookingResultSchema = new mongoose.Schema({

image:[{
    imageUrl:String,
    imageDesc:String
}],

_cookingSetup: {
    type: mongoose.Schema.ObjectId,
    ref: 'CookingSetup'
},
_author: {
    type: mongoose.Schema.ObjectId,
    ref: 'User'
},
_experiment: {
    type: mongoose.Schema.ObjectId,
    ref: 'Experiment'
},

} this schema points to experiment: next schema is the experiment: this schema as you can see points to more schemas:

created: { type: Date, default: Date.now }, _author: { type: mongoose.Schema.ObjectId, ref: 'User' }, name: { type: String, required: true }, description: String, _dish: { type: mongoose.Schema.ObjectId, ref: 'Dish' }, dependantVariable: { name: String, defaultValue: String }, setups: [{ type: mongoose.Schema.ObjectId, ref: 'CookingSetup' }] });

Now the dish also points to author for example

var DishSchema = new mongoose.Schema({ created: { type: Date, default: Date.now }, name : { type: String, required: true }, _image: { type: mongoose.Schema.ObjectId, ref: 'Image' }, description: String, targetScore: { type:Number, required: true

},
//image:{
//    type:String,
//    default:"/static/images/dish_placeholder.png"
//} ,

lastUpdate: {
    type: Date,
    default: Date.now
},
_author: {
    type: mongoose.Schema.ObjectId,
    ref: 'User'
},

} so i can i start from resultcoking -> expriment -> dish -> author and print all that chain?

could it be done with your library in one call?

does it also support one to many?

but the first question is the more important, cause with out it , i will need to use several query calls Thanks,