Reputation: 3003
So I'm trying to find all my documents that hasn't images
object, and also count them.
Find within a cursor goes well, as I iterate on the cursor itself so I don't need to wait for fetching, but count takes forever.
I have 11M (11,000,000) records on that collection, it doesn't has any index but _id
so I know I need to create indexes, but I don't know which indexes I would need...
My document structure has integers and strings, but it contains an Object
which is images
.
name (str) | title (str) | images (Object)
The images
object has this structure
red (int) | green (int) | blue (int) | url (str) | filename (str) | path (str) | product (str)
And my query is simple
db.products.find({'images': {'exists': false }}).count()
I've also tried
db.products.count({'images': {'exists': false }})
but as I say, it takes forever to count...
Upvotes: 0
Views: 297
Reputation: 887
Have you tried to index images field?
db.products.ensureIndex({'images':1})
Nested images fields can be accessed using .(dot) notation
Upvotes: 3