-
Type:
New Feature
-
Resolution: Unresolved
-
Priority:
Minor - P4
-
None
-
Affects Version/s: None
-
Component/s: None
-
None
Context
With the Go bson package I can do:
bson.NewObjectIDFromTimestamp(time.Now())
and the generated ObjectID retains its randomness after the timestamp. When I try:
dt = datetime.now() print(ObjectId.from_datetime(dt))
with PyMongo's bson package, I consistently get the same “random” bits back. This is the expected behavior according to the docs, but I think it would be great to provide an API that mimics how Go's API works so that ObjectIDs with an external timestamp source can still be used as IDs without coordination.
this test provides an example of the same behavior as Go's package with the Python package, but the code looks brittle and hard to follow.
Definition of done
There is some API, let's say ObjectId.random_from_datetime(datetime), that allows me to mimic Go's bson.NewObjectIDFromTimestamp() API. The naming of the API is up to the team, of course!