Moment converts date as string for find query and object for aggregate query. How & Why? Moment converts date as string for find query and object for aggregate query. How & Why? mongoose mongoose

Moment converts date as string for find query and object for aggregate query. How & Why?


It's because find provides its results as Mongoose document instances (which can't be freely modified) while aggregate provides its results as plain objects (which can).

So if you want to modify the created_at field in your find results, tell Mongoose to provide plain objects instead by chaining a call to lean():

this.find({},{    "updated_at":1,    "created_at":1,}).lean().exec(callback);


format method returns string. When you use format you want to show to user and is display function.