Mongoose complex (async) virtuals

前端 未结 1 556
庸人自扰
庸人自扰 2020-12-03 18:58

I have two mongoose schemas as follow:

var playerSchema = new mongoose.Schema({
    name: String,
    team_id: mongoose.Schema.Types.ObjectI         


        
相关标签:
1条回答
  • 2020-12-03 19:18

    This is probably best handled as an instance method you add to teamSchema so that the caller can provide a callback to receive the async result:

    teamSchema.methods.getSquad = function(callback) {
      Players.find({ team_id: this._id }, callback);
    });
    
    0 讨论(0)
提交回复
热议问题