I am trying inserting one date value from expressjs to mongodb. I am using mongodb native driver.
The issue is when I am using creating an object and inserting it using that variable , the date is inserted as string. Here is the sample-
var expenseTest = {date: new Date()};
database.collection('expensemaster').insert(expenseTest, function(err, r){
console.log("query executed");
});
Here the the value in DB-
{
"_id" : ObjectId("584f9b6e8c06a5717d10ee59"),
"date" : "2016-12-13T06:55:24.698Z",
}
But when I am inserting the object directly in the insert query its date is returning as ISODate(date).
Here is the sample-
database.collection('expensemaster').insert({date: new Date()}, function(err, r) {
console.log("query executed");
});
The value in db-
{
"_id" : ObjectId("584fba82566fc8787e75a7ed"),
"date" : ISODate("2016-12-13T09:08:18.441Z")
}
My question is - what if I have to use insertMany to insert array of object having date as one of the field.
How can I get date as ISODate(date) in the db.