const groupSchema = new Schema({
name: { type: String,default: "",required: true },participants: [{
type: Schema.Types.ObjectId,ref: 'User'
}],});
const userSchema = new Schema({
username: { type: String,name: { type: String,});
我正在尝试获取给定用户加入的所有组。这是我的尝试
userModel.findOne({ username: data.username },function(err,user) {
if (user) {
groupModel
.find({"participants":{"$in":[user]}
.populate('participants')
.exec(function(err,result) {
.....
}
}
});
我在上面的查询中得到一个空列表 谢谢