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

$where doesn't find equal NumberLong values

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Duplicate
    • Affects Version/s: 2.4.6
    • Fix Version/s: None
    • Component/s: Querying, Shell
    • Labels:
      None
    • Environment:
      linux 64 bit
    • Operating System:
      ALL
    • Steps To Reproduce:
      Hide

      mongos> db.wheretest.remove()
      mongos> db.wheretest.save({a:NumberLong(10), b: NumberLong(10)})
      mongos> db.wheretest.save({a:NumberLong(9), b: NumberLong(10)})
      mongos> db.wheretest.save({a:NumberLong(10), b: NumberLong(9)})
      mongos> db.wheretest.find({$where: "this.a < this.b"},{_id:0,a:1,b:1});//OK
      { "a" : NumberLong(9), "b" : NumberLong(10) }
      mongos> db.wheretest.find({$where: "this.a > this.b"},{_id:0,a:1,b:1});//OK
      { "a" : NumberLong(10), "b" : NumberLong(9) }
      mongos> db.wheretest.find({$where: "this.a == this.b"},{_id:0,a:1,b:1});//NOT OK
      mongos> db.wheretest.find({$where: "this.a.toNumber() == this.b.toNumber()"},{_id:0,a:1,b:1});//WORKAROUND
      { "a" : NumberLong(10), "b" : NumberLong(10) }
      mongos> 

      Show
      mongos> db.wheretest.remove() mongos> db.wheretest.save({a:NumberLong(10), b: NumberLong(10)}) mongos> db.wheretest.save({a:NumberLong(9), b: NumberLong(10)}) mongos> db.wheretest.save({a:NumberLong(10), b: NumberLong(9)}) mongos> db.wheretest.find({$where: "this.a < this.b"},{_id:0,a:1,b:1});//OK { "a" : NumberLong(9), "b" : NumberLong(10) } mongos> db.wheretest.find({$where: "this.a > this.b"},{_id:0,a:1,b:1});//OK { "a" : NumberLong(10), "b" : NumberLong(9) } mongos> db.wheretest.find({$where: "this.a == this.b"},{_id:0,a:1,b:1});//NOT OK mongos> db.wheretest.find({$where: "this.a.toNumber() == this.b.toNumber()"},{_id:0,a:1,b:1});//WORKAROUND { "a" : NumberLong(10), "b" : NumberLong(10) } mongos>

      Description

      It seems that we need to call .toNumber() even if solely NumberLong values are tested on equality (==) by $where (see below steps to reproduce). The operators > and < work without .toNumer() nevertheless.

        Attachments

          Activity

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: