Du är bara ett steg bort!
Projektgruppschema:
var ProjectGroupSchema = new Schema({
title : String
});
Projektschema:
var ProjectSchema = new Schema({
title : {type : String, default : '', required : true},
group : {type: Schema.Types.ObjectId, ref: 'ProjectGroup' },
_users : [{type: Schema.Types.ObjectId, ref: 'User' }]
});
Användarschema:
var UserSchema = new Schema({
first_name : {type: String, required: true},
last_name : {type: String, required: true},
subscribing : [{type: Schema.Types.ObjectId, ref: 'Project' }]
});
Sedan kan du göra följande:
user.findById(req.userId)
.populate('subscribing')
.exec(function(err, user){
console.log(user.subscribing);
})
Eller:
project.find({
subscriber : req.userId
})
.populate('subscriber')
.populate('group')
.exec(function(err, projects){
console.log(projects);
})