Can't save date object on PyMongo

Skip to first unread message

Jim Zhan

Oct 17, 2009, 2:58:06 AM10/17/09
to mongodb-user
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/home/jim/", line 319, in save
result =, safe=True)
File "build/bdist.linux-i686/egg/pymongo/", line 157,
in save
manipulate, safe)
File "build/bdist.linux-i686/egg/pymongo/", line 232,
in update
message += bson.BSON.from_dict(document)
File "build/bdist.linux-i686/egg/pymongo/", line 550, in
return cls(_dict_to_bson(dict, check_keys))
InvalidDocument: Cannot encode object:, 10, 17)

But it works fine when using datetime.

Michael Dirolf

Oct 17, 2009, 11:51:16 AM10/17/09
PyMongo doesn't support saving date instances. The server doesn't have
a type for dates without times, so there would have to be some
convention used to save dates without times. If you need to save a
date your client should convert it to a datetime instance and you can
save that.
Reply all
Reply to author
0 new messages