Reputation: 2272
I have a date field that is javascript number date and I want to get the string or object of date (like new Date(date)) in find query projection instead of date field itself that is number.
//I want to get
datetime:new Date(date)
//instead of
db.myCollection.find({},{date:1})
thanks.
Upvotes: 2
Views: 53
Reputation: 163
You can use forEach or map function
db.yourCollectionName.find({}).map(function(doc) {
return {
d:new Date(doc.datetime)
};
});
Upvotes: 2