do not use $ne operator
See original GitHub issueIn large collections, the $ne
operator is very inefficient and can make queries slow. (https://docs.mongodb.com/manual/reference/operator/query/ne/ last paragraph).
I recently had to investigate performance troubles we’re having in one of our largest collections and it’s due to the use of this plugin. What I’d suggest is maybe always keeping deleted
as false
and then doing {$eq: false}
to retrieve active documents.
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
NE or <> operator - Progress Software
Compares two expressions and returns a TRUE value if they are not equal. Syntax. expression { NE | <> } expression. expression ...
Read more >$ne — MongoDB Manual
$ne selects the documents where the value of the field is not equal to the specified value . This includes documents that do...
Read more >What is the $ne operator in MongoDB? - Educative.io
It is one of the comparison operators in MongoDB. It is used to match the documents whose field value is not equal to...
Read more >NE Operator - Rocket Software
NE Operator. NE is the relational operator NOT EQUAL TO, used in selection expressions to compare an attribute to a constant or to...
Read more >Logical NOT (!) - JavaScript - MDN Web Docs - Mozilla
The logical NOT (!) (logical complement, negation) operator takes truth to falsity and vice versa. It is typically used with boolean (logical) values....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This type of changes can affect existing users and I really try to keep back compatibility with older versions. This is the main reason why I introduce new option
use$neOperator
so you can override default behavior (default is{use$neOperator: true}
).This new option will cover both scenarios.
https://github.com/dsanel/mongoose-delete/blob/master/test/index.js#L1598-L1654
Hope this will help @gabzim? 😉
FYI I just tried doing a comparison, and inside a collection of +1mn documents, and I didn’t see any noticeable difference.
Am I missing something?
Using
deleted: {$ne: true}
Using
deleted: false