Multiple populates - mongoosejs

后端 未结 8 1762
傲寒
傲寒 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:08

    UPDATE:
    This solution remains for the version 3.x of Mongoose
    http://mongoosejs.com/docs/3.8.x/docs/populate.html
    but is no longer documented for >= 4.x versions of Mongoose and so the answer from @JohnnyHK is the only valid one for now on.

    ORIGINAL POST
    If you're using Mongoose >= 3.6, you can pass a space delimited string of the path names to populate:

    OrderModel.find()
        .populate('user meal')
        .exec(function (err, results) {
             // callback
        });
    

    http://mongoosejs.com/docs/populate.html

提交回复
热议问题