I have an intermediate experience of Mongodb, and Javascript is not a language I master a lot.
I used the solution proposed in this topic but this is very heavy for my RAM.
I found partially an other way to solve my problem. Inspired by this page and Kamil Naja's answer I wrote this code:
db.coll.find(
{ $where:
function() { return (new Set(this.field).size !== this.field.length)}
}
)
It's more convenient to write, it's faster but it misses something particular for my problematic. I only want to count the duplicates of integer numbers.
For instance, here two arrays with different contents and both have duplicates but not from the same type:
- [1,2,3,4,5,6,6,7,8,'a','t'], array in
field
from file 1 - [1,2,3,4,5,6,7,8,'a','a'], array in
field
from file 2
With the current code above, it will select the two files, while I want the query to only return the file 1 because there are duplicates of integers.
How can I implement this condition, still using find()
and not aggregate()
?