Extracting datetime fields in ISO format from all documents in PyMongo to avoid JSON Serialization error

Hello,

Is it possible to extract all documents from a collection with the datetime fields in ISO format when using PyMongo? Is there a property I can set at the collection level ? This is probably a very basic question. Thanks for any suggestions.

Best regards.

Hi @Satya_Tanduri welcome to the community!

Could you elaborate on what you mean by “extract in ISO format using pymongo”? What are you trying to achieve? Are you trying to export the collection using pymongo? What are the result of your efforts so far?

If you need to export the whole collection, you can use the mongoexport tool. Note that the tools (mongoexport/mongoimport/mongodump, etc.) are downloaded separately starting from MongoDB 4.4.

Best regards,
Kevin

Sorry for the late response. I have tried out MongoExport and MongoDump utilities. I am exploring developer options (Python/Java) etc right now. I see that there is DATETIME Data type serialization issue and the work around seems to be using JSON_UTIL. I managed to get that to work for my purpose. Thank you so much for your guidance.

1 Like