Last active
February 7, 2017 18:33
-
-
Save amitsaxena/6977506 to your computer and use it in GitHub Desktop.
How to get object creation timestamp from BSON object id using mongoid, and do range queries on it.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# To get the created at timestamp | |
sample_object.id.generation_time | |
# To do range queries | |
start = Moped::BSON::ObjectId.from_time(Time.now.beginning_of_day) | |
finish = Moped::BSON::ObjectId.from_time(Time.now.end_of_day) | |
MyModel.where(:id => {'$gt' => start, '$lt' => finish}).count |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment