{
"A" : [],
}
OR
{
"A" : [
{
"_id" : 1,
"Name" : "ASDF"
},
{
"_id" : 2,
"Name" : "GHJKL"
}
],
}db.getCollection('X').distinct('A')[
undefined,
{
"_id" : 1,
"Name" : "ASDF"
}, ...
]actually works fine and returns the values we expect. If we then add an index on this Field ( db.X.createIndex({“A”:1,{Name:”IX_A”}) and run this query again, there is suddenly an item undefined:
Hi,
Depending on your use case, Partial Indexes is likely what you’re after.
For example you can create:
db.collection.createIndex({"A":1}, {partialFilterExpression:{"A":{"$exists":true}}})
Regards,
Wan.