Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-50444

mongo shell serializes large NumberLongs incorrectly

    • Type: Icon: Bug Bug
    • Resolution: Works as Designed
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None
    • Query
    • ALL
    • Hide

      Steps to reproduce issue #1:

      > db.c.insert({x: NumberLong(9223372036854774800)})
      WriteResult({ "nInserted" : 1 })
      > db.c.find()
      { "_id" : ObjectId("5f3f93740f6105e040a46651"), "x" : NumberLong("9223372036854774784") }
      

      Steps to reproduce issue #2:

      > db.c.insert({x: NumberLong(9223372036854775600)}) // This number should fit in BSON NumberLong
      Error: number passed to NumberLong must be representable as an int64_t :
      @(shell):1:17
      
      Show
      Steps to reproduce issue #1: > db.c.insert({x: NumberLong(9223372036854774800)}) WriteResult({ "nInserted" : 1 }) > db.c.find() { "_id" : ObjectId( "5f3f93740f6105e040a46651" ), "x" : NumberLong( "9223372036854774784" ) } Steps to reproduce issue #2: > db.c.insert({x: NumberLong(9223372036854775600)}) // This number should fit in BSON NumberLong Error: number passed to NumberLong must be representable as an int64_t : @(shell):1:17

      I've noticed couple of issues with mongo shell

      1. mongo shell is serializing large NumberLong values (which are valid) incorrectly, and send wrong value to the server.
      2. We are enforcing a limit on numbers that could fit into BSON NumberLong data type.

      Both these issues seem to be because we are converting the number into double first and then interpreting it as 'int64_t'

            Assignee:
            backlog-server-query Backlog - Query Team (Inactive)
            Reporter:
            arun.banala@mongodb.com Arun Banala
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: