Currently i have a collection with millions of data which have datetime that are stored in strings therefore if i try to convert the date using $datefromString it can be really slow. But instead i use ObjectId.fromDate to speed up the query.Below are one of the example of query when i try to aggregate/find data of last N - Days/Month using ObjectID that are converted into date.
var monthStart = new Date();
monthStart.setMonth(monthStart.getMonth() - 12);
db.REPORTGPS.find({
_id: {
$gte: ObjectId.fromDate(monthStart),
}
})
The query above worked fine for me, but the question that i would like to ask is how do i specify mongodump date range using objectID. I have seen queries of mongodump with specific date range , however i have not found any example that use ObjectID.fromDate. The closest that i have found is from this person and the queries looked something like this.However i would like to use ObjectID instead of attributes with Date type.
mongodump -d correos -c observations --query "{\"ts\":{\"\$gt\":{\"\$date\":`date -d 2015-09-01 +%s`000},\"\$lte\":{\"\$date\":`date -d 2015-11-05 +%s`000}}}"
Source : mongodump all files from last 2 days
TLDR : how do i dump last N-days but specify the date range using ObjectID instead of Date