Long contructor and NumberLong helper warnings are not consistent

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Unresolved
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Shell API
    • None
    • Environment:
    • 2
    • None
    • Developer Tools

      Problem Statement/Rationale

      BSON's Long type constructor does not warn the user about loss of precision when used without a string input.

      > Long(8589869056)
      Long('4294901760')

      Instead, the NumberLong helper emits a warning when called with the same value.

      > NumberLong(8589869056)
      Warning: NumberLong: specifying a number as argument is deprecated and may lead to loss of precision, pass a string instead Long('8589869056')

      Long contructor should behave in the same way because the shell provides an interactive session where warnings are, usually, seen by users.

      As an example of consistent behaviour, you can see the Decimal128 contructor and the NumberDecimal helper.

      > NumberDecimal(8589869056)
      Warning: NumberDecimal: specifying a number as argument is deprecated and may lead to loss of precision, pass a string instead
      Decimal128('8589869056')
      
      > Decimal128(8589869056)
      BSONError: Decimal128 must take a Buffer or string

      Steps to Reproduce

      Just call Long(8589869056) in the mongo shell.

      Expected Results

      A warning or an error.

            Assignee:
            Unassigned
            Reporter:
            Alessandro Miliucci
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: