var UserSchema = Schema (
{
android_id: String,
rooms: [{ type: Schema.Types.ObjectId, ref: 'Chatrooms'}],
location: {country: String, state: String, coordinates: { latitude: String, longitude: String}}
});
var RoomSchema = Schema
({
Roomname: {type: String},
ids: {type: Array},
});
Users
.find({android_id: {$ne: userID}, 'location.state': LocationArray.state, 'location.country': LocationArray.country})
.populate({
path: 'rooms',
match: {'rooms.ids': {$nin: [userID]}},
select: 'ids'
})
.exec(function(err, found) {
})
我想在一个州和国家中找到所有不包括我自己的用户,我不在他们的ids数组中。这可能与填充?
答案 0 :(得分:2)
希望这可以帮到你。
Users
.find({android_id: {$ne: userID}, 'location.state': LocationArray.state, 'location.country': LocationArray.country})
.populate({
path: 'rooms',
match: {'ids': {$nin: [userID]}},
select: 'ids'
})
.exec(function(err, found) {
if(found){
vettings = found.filter(function (doc) {
return doc.ids;
});
}
})