I've a mongo db collection as below.
{
"_id": {
"$oid": "57048f2f60b18f8e186e65b6"
},
"ID": 1,
"Room_ID": 303,
"StartTime": "2016-03-12T11:00:00Z",
"EndTime": "2016-03-12T12:00:00Z",
"Login_ID": "ABCDE"
}
I'm using db.collection.find() query to fetch the results. I am trying to display the date in two parts 1. DD-MM-YY and 2. HH-MM-SS.
I've two ideas for this. 1. Get the date in the desired format from collection.find() command or 2. After fetching the records into cursor, parse it in angularjs code to separate date and time values.
I've tried the $dateToString of mongodb but couldn't get the results. In fact I am confused with it.
db.RoomReservation.aggregate({ $project: {"Login_ID": "ABCDE", dt: { $dateToString: { format: "%Y-%m-%d", date: "$StartTime"}}}});
assert: command failed: {
"errmsg" : "exception: can't convert from BSON type String to Date",
"code" : 16006,
"ok" : 0
} : aggregate failed
Can someone please help me in getting the output of collection.find() in the following format
Room_ID, Date, StartTime, EndTime, Login_ID
303, 2016-03-12, 11:00, 12:00, ABCDE
3.2.4version