Multiple populates - mongoosejs

后端 未结 8 1756
傲寒
傲寒 2020-12-04 17:33

Just a simple query, for example with a double ref in the model.

Schema / Model

var OrderSchema = new Schema({

    user: {
                 


        
8条回答
  •  隐瞒了意图╮
    2020-12-04 18:09

    To populate multiple fields with array of objects in controller/action function, model of both is already referred in schema of post

    post.find({}).populate('user').populate('comments').exec(function (err,posts)
        {
        
        if(err)
        {
            console.log("error in post");
        }
        
            return  res.render('home',{
                h1:"home Page",
                posts:posts,
                
                });      
            });
    

提交回复
热议问题