Created
February 4, 2019 07:09
-
-
Save atharvai/f1936b5a1c8a70ce5570e5646e40289c to your computer and use it in GitHub Desktop.
BSON timestamp construct & deconstruct example
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
from bson import Timestamp | |
from datetime import datetime | |
ts=Timestamp(datetime.utcnow(), 1) | |
def ts_to_int(ts): | |
return (ts.time << 32) + ts.inc | |
def int_to_ts(t): | |
return Timestamp(t>>32, t & (2**32)-1) | |
print(ts_to_int(ts)) | |
# 6654037895042564097L | |
print(int_to_ts(6654037895042564097L)) | |
# Timestamp(1549263926, 1) |
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
pymongo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment