0

I am using a setup wherein I am using UNIX command line Javascript. An example of my code is:

var query1 = db.sample.aggregate({query body})

I am piping the output of this Javascript into a file when I run it in UNIX using the command:

mongo dbname query1.js > queryout.txt

So this is the setup. My requirement is that I need to fetch system date using a MongoDB query and I need to format it into YYYYMMDD format in the Javascript.

I already store time as ISODate(YYYY-MM-DDTHH:MM:SSZ) in the MOngoDB.

If i use a query to fetch it into a variable, is there any way to bring it into my required format in the same script?

Or as another option can I use something like sed on the output file and do the formatting there?

Thank you in advance for your time and help.

Manus
  • 779
  • 2
  • 9
  • 19
  • 1
    What do you mean by "fetch system date using a MongoDB query?" `var date=new Date().toISOString()` – WiredPrairie Nov 20 '13 at 17:06
  • Sorry about that...a bit of a redundant request there. I already have the date in the format I mentioned above. Now the only point is to format it. But thanks for the solution to getting system date. I may use it instead of the recorded date in DB. – Manus Nov 20 '13 at 17:09
  • I found this just now.http://stackoverflow.com/questions/1056728/formatting-a-date-in-javascript?rq=1. Will it help?? – Manus Nov 20 '13 at 17:11
  • It might help ... I really don't understand what you're trying to do. – WiredPrairie Nov 20 '13 at 17:15

0 Answers0