Hi, Bernie,
I want to correct my former statement:
Oh, I've tried to add query conditions to limit the upper and lower boundary of the datetime field (1970-01-01 ~ 2038-01-01), it doesn't work.
It actually works. I think i was putting the restriction upon only one problematic datetime field (there are two)...
Well, there are also negative values causing "OverflowError: date value out of range":
data: _idP??vh??Kq~?% ctime??';gid 11395990ptid 10411796 start_timeH?,;status, position: 32, seconds: 1353577590.72
data: _idP??vh??Kq~?% ctime??';gid 11395990ptid 10411796 start_timeH?,;status, position: 89, seconds: 1353667517.0
data: _idP??ph??Kq~?? ctime?]?';gid 11420441ptid 10454924 start_time???'č??status, position: 32, seconds: 1353578864.03
data: _idP??ph??Kq~?? ctime?]?';gid 11420441ptid 10454924 start_time???'č??status, position: 89, seconds: -1.2560136087e+11
Traceback (most recent call last):
So, it is necessary to add another restriction(gt 1970). My application runs without exceptions in this way:
cur = col.find({
'ctime': {'$lt': datetime.datetime(2038,1,1,0,0), '$gt': datetime.datetime(1970,1,1,0,0)},
'start_time': {'$lt': datetime.datetime(2038,1,1,0,0), '$gt': datetime.datetime(1970,1,1,0,0)}
}, fields=['ptid', 'ctime', 'start_time', 'status', 'gid', ])
Hence mongodb allows other drivers (like php) to submit such kind of values while they cannot get represented in Python Datetime type, i think that we have two options to deal with it:
1) Introduce an exception mechanism for such situations, to inform the users ( of the python driver ) what is happening. Prompt them to add query restrictions so that their codes runs without exceptions but some records maybe ignored, just like what you did to me haha :)
2) Cutting the overflowed values into the range that python datetime can handle. (This way we save the record, but drop the field.)
Personally I prefer the first one.
About the C extension:
The moral of the story is always use PyMongo's C extensions if at all possible. :-)
I'm glad to get known about the existence of the C extension. It has been a while I setup my environment. Next time I will try it out, i promise :D
Thanks for all of you, for your attentions and helps :)
Guti