Can't save date object on PyMongo

3953 views
Skip to first unread message

Jim Zhan

unread,
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/test.py", line 319, in save
result = self.store.save(self.__dict__, safe=True)
File "build/bdist.linux-i686/egg/pymongo/collection.py", line 157,
in save
manipulate, safe)
File "build/bdist.linux-i686/egg/pymongo/collection.py", line 232,
in update
message += bson.BSON.from_dict(document)
File "build/bdist.linux-i686/egg/pymongo/bson.py", line 550, in
from_dict
return cls(_dict_to_bson(dict, check_keys))
InvalidDocument: Cannot encode object: datetime.date(2009, 10, 17)

But it works fine when using datetime.

Michael Dirolf

unread,
Oct 17, 2009, 11:51:16 AM10/17/09
to mongod...@googlegroups.com
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
Forward
0 new messages