您只有一步之遥!
项目组架构:
var ProjectGroupSchema = new Schema({ title : String});项目架构:
var ProjectSchema = new Schema({ title : {type : String, default : '', required : true}, group : {type: Schema.Types.ObjectId, ref: 'ProjectGroup' }, _users : [{type: Schema.Types.ObjectId, ref: 'User' }]});用户架构:
var UserSchema = new Schema({ first_name : {type: String, required: true}, last_name : {type: String, required: true}, subscribing : [{type: Schema.Types.ObjectId, ref: 'Project' }]});然后,您可以执行以下操作:
user.findById(req.userId) .populate('subscribing') .exec(function(err, user){ console.log(user.subscribing); })要么:
project.find({ subscriber : req.userId }) .populate('subscriber') .populate('group') .exec(function(err, projects){ console.log(projects); })


