I have these Mongoose Schemas
var UserSchema = new Schema({
pseudo: {type:String},
groups: [{type:Schema.Types.ObjectId, ref:'Groups'}],
last_messages: [{type: Number}],
});
var GroupSchema = new Schema({
messages: [{type: Schema.Types.ObjectId, ref:'Messages'}],
name : {type:String},
picture: {type: String}
});
In UserSchema, last_message is linked to groups. last_message[i]
contains the greatest timestamp of message received by user related to group[i]
I want to populate User by group and in Group populate Message taking only message which timestamp is greater than last_message[i]
where i
is the index of the group which is being populated.
How can I do that?