Код
from pymongo import MongoClient
connection = MongoClient(
host="localhost",
)
dbm = connection['test']
a = dbm.UserStat.find_one({'_id': 119510})
Результат:
Traceback (most recent call last):
File "s.py", line 10, in <module>
a = dbm.UserStat.find_one({'_id': 119510})
File "/home/w2/env/lib/python3.4/site-packages/pymongo/collection.py", line 1109, in find_one
for result in cursor.limit(-1):
File "/home/w2/env/lib/python3.4/site-packages/pymongo/cursor.py", line 1134, in next
if len(self.__data) or self._refresh():
File "/home/w2/env/lib/python3.4/site-packages/pymongo/cursor.py", line 1057, in _refresh
self.__collation))
File "/home/w2/env/lib/python3.4/site-packages/pymongo/cursor.py", line 947, in __send_message
codec_options=self.__codec_options)
File "/home/w2/env/lib/python3.4/site-packages/pymongo/helpers.py", line 142, in _unpack_response
"data": bson.decode_all(response[20:], codec_options)}
bson.errors.InvalidBSON: invalid length or type code
А просто из консоли mongo
Все нормально отрабатывает:
mongo
MongoDB shell version: 2.6.12
connecting to: test
>
>
>
>
>
> db.UserStat.find({_id: 119510}).pretty();
{
"_id" : 119510,
"stat" : {
"17581" : [
[
'1',
'ISODate("2015-12-01T09:10:00Z")'
],
[
'1',
'ISODate("2015-12-01T11:12:03Z")'
],
[
'1',
'ISODate("2015-12-01T14:12:55Z")'
],
[
'1',
'ISODate("2015-12-01T23:51:08Z")'
],
и т.д.
Нашел причину почему она возникает:
Got this error today and know what caused it:
MongoDB allows inserting arbitarly big dates, i.e. ISODate("10217-06-06T00:00:00Z") (not with the actual ISODate(str) constructor in the console though, that overflows). The python datetime lib only supports 4 digit years (until 9999), which is why it overflows when trying to convert the long timestamp into a datetime instance.
https://github.com/mongodb-labs/mongo-connector/is...
Но, как вылечить пока не ясно.