To query for distinct values in Mongoose and Node, we call the distinct
method.
For instance, we write
MyModel.find().distinct("_id", (error, ids) => {
// ...
});
to call distinct
to return an array of distinct values.
We get the entries that have distinct _id
values.
And then we get the _id
values from ids
in the callback.