0

I try to create an ISODATE in pymongo without using datetime module. But unfortunately, I didn't reach my goal.

db.cesars.update_one({"titre":"Maman(s)"},{"$set":{"genre":"Court métrage",
"date_sortie":"new Date('2015-08-28')"},"$setOnInsert":{"évaluations":[]}},True)

Actually I wanted that created an ISODATE but this update leads me to have an string instead of ISODATE object for "date_sortie".

Can someone help me please ?

Thank you

Jacko Myo
  • 1
  • 1

1 Answers1

0

You need to pass your dates as python datetime objects. Pymongo shall translate your datetime object to ISODate.

import datetime

db.cesars.update_one({"titre":"Maman(s)"},{"$set":{"genre":"Court métrage",
"date_sortie":datetime.datetime(2015,8,28,0,0)},"$setOnInsert":{"évaluations":[]}},True)

This pymongo command would set the date appropriately.

Yayati Sule
  • 1,601
  • 13
  • 25
  • Like I said beforce is that possible without using datetime module ? I want to find another way to deal with it. – Jacko Myo May 02 '19 at 13:19
  • No there isnt. The whole point of using a Database Driver is to translate you Language Native Data Structures to the ones the Database would understand. You need to explicitly mention in your question what exactly is it that you want to use. – Yayati Sule May 02 '19 at 13:38