mLC
mLC

Reputation: 693

MongoDB: find records for last X days (in strict JSON)

Finding records for last X days only can be done in mongo Shell Mode with

db.some_collection.find({"some_date":{$gte: (newDate((newDate()).getTime() - (X * 24 * 60 * 60 * 1000)))}})

My question: is there a strict JSON equivalent to this command or not?

Upvotes: 2

Views: 277

Answers (1)

Jonathan
Jonathan

Reputation: 2738

I would much rather have this be false but it seems like there is no way to do a strict JSON search for datetime in mongo. You might want to store time as a string (unix timestamp) and then search for it like a string or use non JSON query with date object

Upvotes: 2

Related Questions