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

$where doesn't find equal NumberLong values

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.4.6
    • Component/s: Querying, Shell
    • None
    • Environment:
      linux 64 bit
    • ALL
    • 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>

      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.

            Assignee:
            Unassigned Unassigned
            Reporter:
            kay.agahd@idealo.de Kay Agahd
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: