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

From: Adam Dohnal <dohnal.adam@xxxxxxxxx>
To: mongodb-user <mongodb-user@xxxxxxxxxxxxxxxx>
Date: Mon, 25 Apr 2016 05:25:14 -0700 (PDT)
Why ads?
I have tried aggregation framework, but when I want distinct values across 
whole collection, I can't use $match stage and $group stage seems that 
doesn't use indexes as well.

db.items.aggregate([{$unwind: "$stock"}, {$group: {_id: "$stock.size"}}], {
explain: true})
{
  "stages" : [
    {
      "$cursor" : {
        "query" : {
        
        },
        "fields" : {
          "stock" : 1,
          "_id" : 0
        },
        "queryPlanner" : {
          "plannerVersion" : 1,
          "namespace" : "local.items",
          "indexFilterSet" : false,
          "parsedQuery" : {
            "$and" : [ ]
          },
          "winningPlan" : {
            "stage" : "COLLSCAN",
            "filter" : {
              "$and" : [ ]
            },
            "direction" : "forward"
          },
          "rejectedPlans" : [ ]
        }
      }
    },
    {
      "$unwind" : "$stock"
    },
    {
      "$group" : {
        "_id" : "$stock.size"
    }
  }
],
"ok" : 1
}


-- 
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/b5bed2ab-f660-49fd-8ff2-9e33b4c6a7f2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Why ads?