-2

I have a large query running on a collection pulling back the date in NumberLong format, I then export to a .csv where I run a formula to convert the date to a format a human can use. Scrolling the web I am not able to find a clear way of pulling the date in 'YYY-MM-DD' format and not the NumberLong on the fly. Has anyone managed this?

Tom Zych
  • 13,329
  • 9
  • 36
  • 53
  • Hi Thomas, welcome to Stackoverflow! Questions need to have a [clear problem statement](http://stackoverflow.com/help/mcve). If you provide a code sample, someone may be able to help you with this. – Michelle Welcks Nov 18 '15 at 23:41

1 Answers1

0

If you are doing this as a once off action, one way of doing this is to use the forEach() method to convert the date and inject the new converted object into a temporary collection. Then dump that collection to CSV.

Something like this:

db.myCollection.find().forEach(function(element) {
    element.dateField = new Date(element.dateField);
    db.myTempCollection.insert(element);
});

Otherwise, I recommend using your programming language of choice and implementing a program or script to do the conversion.

ced-b
  • 3,957
  • 1
  • 27
  • 39