-
Type:
New Feature
-
Resolution: Done
-
Priority:
Trivial - P5
-
Affects Version/s: 1.2.4
-
Component/s: None
-
None
-
None
-
Fully Compatible
-
None
-
None
-
None
-
None
-
None
-
None
Since an ObjectId includes the current timestamp, some people are using that to get document creation time instead of having a separate "created_at" timestamp field.
With this practice, however, a need arises to be able to create ObjectIds at arbitrary points in time. This is especially needed in testing and importing data from other sources.
The `ObjectId.from_time` method, while useful for queries, can't be used for generating real IDs because it doesn't ensure that they are unique.
My idea is: first change the private `generate` method to accept an optional time object (but default to Time.now, to keep present functionality), then change the ObjectId constructor to accept a timestamp and pass it on to `generate`.
The end usage would be in the form of `BSON::ObjectId.new(time)`.