Skip to content

Instantly share code, notes, and snippets.

@inakidelamadrid
Created July 26, 2017 19:20
Show Gist options
  • Save inakidelamadrid/2997651e6d3589c81771baf1e6dd6392 to your computer and use it in GitHub Desktop.
Save inakidelamadrid/2997651e6d3589c81771baf1e6dd6392 to your computer and use it in GitHub Desktop.
Querying MongoDB. Querying by date range and sorting based on date field
db.getCollection('user_sessions').find({ "$and":[
{"created_at": {"$ne": null}},
{"created_at": { $gte : new ISODate("2017-07-12T00:00:00Z") }}
]})
.sort({"created_at": -1})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment