Python:将时间戳转换为数字或字符串

时间:2018-07-22 01:32:04

标签: python mongodb timestamp

def GetLastSignificantTS(self,conn):
    conn=pymongo.MongoClient(uri)
    db=conn.local
    return db.oplog.rs.find_one(sort=[('$natural', pymongo.DESCENDING)])['ts'] 

打印返回值的结果:Timestamp(1532221388,1)

问题:我需要创建一个名为“ 1532221388”的目录,而不是“ Timestamp(1532221388,1)”

帮助!

谢谢

1 个答案:

答案 0 :(得分:0)

基于pymongo源代码https://github.com/mher/pymongo/blob/master/bson/timestamp.py#L66,您可以从时间属性time获取实际时间,因此

db.oplog.rs.find_one(sort=[('$natural', pymongo.DESCENDING)])['ts'].time

应该工作。

相关问题