Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OverflowError: MongoDB can only handle up to 8-byte ints?

I have spent the last 12 hours scouring the web. I am completely lost, please help.

I am trying to pull data from an API endpoint and put it into MongoDB. The data looks like this:

{"_links": {
    "self": {
      "href": "https://us.api.battle.net/data/sc2/ladder/271302?namespace=prod"
    }
  },
  "league": {
    "league_key": {
      "league_id": 5,
      "season_id": 37,
      "queue_id": 201,
      "team_type": 0
    },
    "key": {
      "href": "https://us.api.battle.net/data/sc2/league/37/201/0/5?namespace=prod"
    }
  },
  "team": [
    {
      "id": 6956151645604413000,
      "rating": 5321,
      "wins": 131,
      "losses": 64,
      "ties": 0,
      "points": 1601,
      "longest_win_streak": 15,
      "current_win_streak": 4,
      "current_rank": 1,
      "highest_rank": 10,
      "previous_rank": 1,
      "join_time_stamp": 1534903699,
      "last_played_time_stamp": 1537822019,
      "member": [
        {
          "legacy_link": {
            "id": 9964871,
            "realm": 1,
            "name": "mTOR#378",
            "path": "/profile/9964871/1/mTOR"
          },
          "played_race_count": [
            {
              "race": "Zerg",
              "count": 195
            }
          ],
          "character_link": {
            "id": 9964871,
            "battle_tag": "Hellghost#11903",
            "key": {
              "href": "https://us.api.battle.net/data/sc2/character/Hellghost-11903/9964871?namespace=prod"
            }
          }
        }
      ]
    },
    {
      "id": 11611747760398664000, .....
....

Here's the code:

for ladder_number in ladder_array:
    ladder_call_url = ladder_call+slash+str(ladder_number)+eng_locale+access_token
    url = str(ladder_call_url)
    response = requests.get(url)
    print('trying ladder number '+str(ladder_number))
    print('calling :'+url)
    if response.status_code == 200:
        print('status: '+str(response))
        mmr_db.ladders.insert_one(response.json())

I get an error:

OverflowError: MongoDB can only handle up to 8-byte ints?

Is this because the data I am trying to load is too large? Are the "ID" integers too large?

Oh man, any help would be sincerely appreciated.

_______ EDIT ____________

Edited to include the Traceback:

Traceback (most recent call last):
  File "C:\scripts\mmr_from_ladders.py", line 96, in <module>
    mmr_db.ladders.insert_one(response.json(), bypass_document_validation=True)
  File "C:\Users\me\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pymongo\collection.py", line 693, in insert_one
    session=session),
  File "C:\Users\me\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pymongo\collection.py", line 607, in _insert
    bypass_doc_val, session)
  File "C:\Users\me\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pymongo\collection.py", line 595, in _insert_one
    acknowledged, _insert_command, session)
  File "C:\Users\me\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pymongo\mongo_client.py", line 1243, in _retryable_write
    return self._retry_with_session(retryable, func, s, None)
  File "C:\Users\me\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pymongo\mongo_client.py", line 1196, in _retry_with_session
    return func(session, sock_info, retryable)
  File "C:\Users\me\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pymongo\collection.py", line 590, in _insert_command
    retryable_write=retryable_write)
  File "C:\Users\me\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pymongo\pool.py", line 584, in command
    self._raise_connection_failure(error)
  File "C:\Users\me\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pymongo\pool.py", line 745, in _raise_connection_failure
    raise error
  File "C:\Users\me\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pymongo\pool.py", line 579, in command
    unacknowledged=unacknowledged)
  File "C:\Users\me\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pymongo\network.py", line 114, in command
    codec_options, ctx=compression_ctx)
  File "C:\Users\me\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pymongo\message.py", line 679, in _op_msg
    flags, command, identifier, docs, check_keys, opts)
OverflowError: MongoDB can only handle up to 8-byte ints
like image 358
FLAV10 Avatar asked Sep 27 '18 20:09

FLAV10


1 Answers

The BSON spec — MongoDB’s native binary extended JSON format / data type — only supports 32 bit (signed) and 64 bit (signed) integers — 8 bytes being 64 bits.

The maximum integer value that can be stored in a 64 bit int is: 9,223,372,036,854,775,807

In your example you appear to have larger ids, for example: 11,611,747,760,398,664,000

I’m guessing that the app generating this data is using uint64 types (unsigned can hold x2-1 values).

I would start by looking at either of these potential solutions, if possible:

  • Changing the other side to use int64 (signed) types for the IDs.
  • Replacing the incoming IDs using ObjectId() as you then get a 12 byte ~ GUID for your unique IDs.
like image 126
Matt Lord Avatar answered Oct 13 '22 12:10

Matt Lord