2015-09-03 121 views
0
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) { 
    }) 

我想查找除我自己以外的所有用户,但是我不在他们的ID数组中。这可能与填充?如何过滤model.find查询结果与model.populate查询结果在猫鼬?

回答

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; 
     }); 
    } 
}) 
+0

感谢,但在此之前我开始处理数组我想知道是否有办法用'.populate'进一步筛选我'Users.find'查询结果。 –

+0

如果这是不可能的,我会用你的方法,谢谢。 –