I have an array inside a collection in mongodb as per below.
{
"_id" : ObjectId("53dbb05fa976627439d43884"),
"employee" : [
{
"date" : "1986-03-10"
},
{
"date" : "1986-12-11"
}
]
}
Now I want to find all distinct date and output it to array in nodejs format.
var collection = db.collection('employee');
collection.distinct('employee.date').toArray(function(err, docsa) {
console.log(docsa);
});
};
The problem is I will receive the following error, but those collection.distinct command can be run on mongodb.Anyhow I can avoid the error ?
TypeError: Cannot call method 'toArray' of undefined
Or is there any way I can use collection.find() to get the same output?