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.