How can I project date string or object instead of date number field in mongodb find query?

3477 views mongodb

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 


answered question

Could you show how does your date field look like in database.

1 Answer


You can use forEach or map function

db.yourCollectionName.find({}).map(function(doc) {
    return {
        d:new Date(doc.datetime)

posted this

Have an answer?


Please login first before posting an answer.