2014년 12월 30일 화요일

[mongoose] Statics loading reference list of objects

Here is my code:

var DocSchema = new Schema({
    clauseList: [{
        type: Schema.ObjectId,
        ref: 'Clause'
    }],
    user: {
        type: Schema.ObjectId,
        ref: 'User'
    }
});
DocSchema.statics.load = function(id, cb) {
    this.findOne({
        _id: id
    }).populate('user', 'name username').exec(cb);
};

I want to automatically load clauses list like loading the user. Help me please!


댓글 없음:

댓글 쓰기