Create an ISODate with pyMongo

前端 未结 4 1719
春和景丽
春和景丽 2020-12-01 06:22

I\'ve been trying to find a way to create an ISODate object whith pyMongo client, but without any success so far.

I use http://pypi.python.org/pypi/pymongo3 client,

4条回答
  •  长情又很酷
    2020-12-01 07:03

    Actually that does not work either. When you try to use either utcfromtimestamp or fromtimestamp, the program errors out saying that it needs a float. Just parse the string into a date time object and use that directly in the Mongodb. filter

    from_dt = datetime.strptime('2018-04-01','%Y-%m-%d')
    #from_dts = datetime.utcfromtimestamp(from_dt)
    to_dt = datetime.strptime('2018-04-30','%Y-%m-%d')
    #to_dts = datetime.utcfromtimestamp(to_dt)
    filterCondition = { 
        "LastLogin" : { "$lte" : to_dt},
        "LastLogin" : { "$gte" : from_dt}
    }
    

    And then

    db[(colName)].find({ "" : filterCondition }) 
    

    Would work...

提交回复
热议问题