Filters - nin not working with near.

246 views Asked by At

I'm having an issue with the nin and near filters. Whenever I use them both to query data from my MongoDB, I get an empty set of results.

Here's the code I'm using :

AppUser.find({where : {years_of_experience:{neq : null} ,location: {near: user_location}, id:{nin : swiped_profiles}}, limit:10 },function(err, users){
   //SOME CODE
});

If I use only nin it works fine, same goes for near. It's the combination of nin and near that doesn't work !

1

There are 1 answers

1
JSimonsen On

Instead of using $nin, I would try running with $ne for Not Equals since $nin is used when the field value is not in the specified array or the field does not exist:

db.whatever.find( { qty: { $nin: [ 5, 15 ] } } )

Whereas $ne (not equals) would be for a specific value:

db.whatever.find( { name: { $ne: "Bob" } } )