Search code examples
pythonmongodbpymongoisodate

How to insert a timestamp value into the ISODate type on MongoDB by Python?


The timestamp value will be transfer to the ISODate type on MongoDB by Node.js & Mongoose.

ex. 123456789012 ---> ISODate(xxxx)

But it will be save and still in Number type on MongoDB when I use Python & pymongo.

ex. 123456789012 ---> 123456789012 ...

How to insert a timestamp value into the ISODate type on MongoDB by Python?


Solution

  • You should convert it to a datetime.datetime object, and save that. pymongo, I assume you are using that, will convert it to the right format for you.