const groupSchema = new Schema({
name: { type: String, default: "", required: true },
participants: [{
type: Schema.Types.ObjectId,
ref: 'User'
}],
});
const userSchema = new Schema({
username: { type: String, default: "", required: true },
name: { type: String, default: "", required: true },
});
Я пытаюсь получить все группы, к которым присоединен данный пользователь. Это моя попытка
userModel.findOne({ username: data.username }, function(err, user) {
if (user) {
groupModel
.find({"participants":{"$in":[user]}
.populate('participants')
.exec(function(err, result) {
.....
}
}
});
Я получаю пустой список по вышеуказанному запросу. Спасибо