question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

do not use $ne operator

See original GitHub issue

In 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:closed
  • Created 5 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
dsanelcommented, Sep 3, 2019

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? 😉

0reactions
simplenotezycommented, May 18, 2022

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}

image

Using deleted: false

image
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found