Currently, I am attempting to retrieve the previous day's documents from MongoDB by utilizing a bash script along with JavaScript.
I have successfully employed JS to send the query to MongoDB. However, I encountered an issue when handling the date format. The date retrieved appears like this:
2015-7-3 6:2:00
In my database, the records are formatted as follows:
2015-07-03 06:02:00
var d = new Date();
db.mycoll.find({ "requestedDateTime" : { $gte :d.getFullYear()+'-'+(d.getUTCMonth() + 1)+'-'+(d.getDate() - 1)+' 06:00:00' }});
The above snippet demonstrates how the query is executed at present. It's crucial that this operation occurs daily within the cronjob schedule. Moreover, if there exists an alternative method that does not require the use of JavaScript, I would be keen on exploring those options as well.