nodejs - mongodb - how to find all where a != b?
12,021
Solution 1
The answer can be found here
nodejs - mongodb - how to find all where a != b?
Solution 2
You can use the not equals '$ne' for comparation
collection.findAll({a: {'$ne':b }}, function(err, cursor) {});
Check out this advanced queries manual page for more detailed explanations.
Author by
angry kiwi
Updated on June 13, 2022Comments
-
angry kiwi almost 2 years
this is how I imagine it
//b is variable collection.findAll({a:'!'+b}function(err, cursor) { });
What the correct way to that query, find all result where a != b ?
-
angry kiwi almost 13 yearsI tested the code, it will fetch everything that equals a. :(
-
Atzoya almost 13 yearsTry the same query in your mongodb console window like this: db.nameOfCollection.find({a: {'$ne':b}}). It should return the documents from the collection where a != b. If it does, the problem is elsewhere and not in the code snippet from your question
-
Atzoya almost 13 yearsalso try using collection.find() instead of findAll()