I am utilizing mongodb3.0.5 and my database collection appears as follows:
{
"_id" : "xxxxxxxxxxxxxxx",
"SchoolId" : 1,
"ActivationTimestamp" : ISODate("2015-09-22T13:01:58.000Z"),
"PersonDetails" : [
{
"Name" : "John",
"AddressZone" : 6,
},
{
"Name" : "Mary",
"AddressZone" : 5,
},
],
"CreationTimestamp" : ISODate("2015-11-10T10:55:00.009Z")
}
My javascript file is structured like so:
var printData = function(doc){
print(doc.CreationTimestamp+","+doc.SchoolId+","+doc.PersonDetails.Name+","+doc.PersonDetails.AddressZone)
};
var cur =
db.test.aggregate([
{$match: {_id: "xxxxxxxxxxxxxxx"}},
{$unwind: '$PersonDetails'}]);
cur.forEach(printData);
When I execute this command:
.\mongo localhost/test test.js > output.txt
The resulting output (only showing a sample) is:
Tue Sep 22 2015 14:01:58 GMT+0100 (GMT Daylight Time),1,John,6
However, I want the date to be displayed in the format of:
22/09/2015 14:01:58
Is there a method or solution to format the datetime as indicated above?