Re: Distinct on array of embedded documents doesn't use index?

From: Asya Kamsky <asya@xxxxxxxxxxx>
To: mongodb-user <mongodb-user@xxxxxxxxxxxxxxxx>
Date: Mon, 25 Apr 2016 20:52:09 -0400
Why ads?
You can vote up this ticket: https://jira.mongodb.org/browse/SERVER-13298

Though this is also related to  https://jira.mongodb.org/browse/SERVER-2104

On Sun, Apr 24, 2016 at 10:03 AM, Adam Dohnal <dohnal.adam@xxxxxxxxx> wrote:
Hello,

let's say I have collection of documents like this, so there is array field
with embedded document

{
  _id: 1,
  item: "abc",
  stock: [
    { size: "S", color: "red", quantity: 25 },
    { size: "S", color: "blue", quantity: 10 },
    { size: "M", color: "blue", quantity: 50 }
  ]
}


I have created a multikey index on "stock.size", but when I run
db.items.distinct("stock.size") the whole collections is scanned. This is
the result of db.runCommand({distinct: "items", key: "stock.size"})


"stats" : {

               "n" : 1730969,

               "nscanned" : 0,

               "nscannedObjects" : 1730969,

               "timems" : 3178,

               "planSummary" : "COLLSCAN"

       }


What can I do in order to use that index?

--
You received this message because you are subscribed to the Google Groups
"mongodb-user"
group.

For other MongoDB technical support options, see:
https://docs.mongodb.org/manual/support/
---
You received this message because you are subscribed to the Google Groups
"mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to mongodb-user+unsubscribe@xxxxxxxxxxxxxxxx.
To post to this group, send email to mongodb-user@xxxxxxxxxxxxxxxx.
Visit this group at https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit
https://groups.google.com/d/msgid/mongodb-user/33b743ef-47eb-415f-958a-01ec9a4d3d02%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



-- 
Asya Kamsky
Lead Product Manager
MongoDB
Download MongoDB - mongodb.org/downloads
Free MongoDB Monitoring - cloud.mongodb.com
Free Online Education - university.mongodb.com
Get Involved - mongodb.org/community
We're Hiring! - https://www.mongodb.com/careers

-- 
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.

For other MongoDB technical support options, see: https://docs.mongodb.org/manual/support/
--- 
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user+unsubscribe@xxxxxxxxxxxxxxxx.
To post to this group, send email to mongodb-user@xxxxxxxxxxxxxxxx.
Visit this group at https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/CAOe6dJAO%2Bku4OJokwaxFwoPDF%2B-vpny7GjK0U2v3_B8OCR-QFw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Why ads?