@@ -3,7 +3,7 @@ const { assert: test } = require('../shared');
3
3
const { expect } = require ( 'chai' ) ;
4
4
const sinon = require ( 'sinon' ) ;
5
5
const { setTimeout } = require ( 'timers' ) ;
6
- const { ObjectId, Long, Binary, ReturnDocument, CursorResponse } = require ( '../../mongodb' ) ;
6
+ const { Code , ObjectId, Long, Binary, ReturnDocument, CursorResponse } = require ( '../../mongodb' ) ;
7
7
8
8
describe ( 'Find' , function ( ) {
9
9
let client ;
@@ -450,6 +450,51 @@ describe('Find', function () {
450
450
}
451
451
} ) ;
452
452
453
+ it ( 'shouldCorrectlyPerformFindByWhere' , {
454
+ metadata : {
455
+ requires : {
456
+ topology : [ 'single' , 'replicaset' , 'sharded' , 'ssl' , 'heap' , 'wiredtiger' ]
457
+ }
458
+ } ,
459
+
460
+ test : function ( done ) {
461
+ var configuration = this . configuration ;
462
+ var client = configuration . newClient ( configuration . writeConcernMax ( ) , { maxPoolSize : 1 } ) ;
463
+ client . connect ( function ( err , client ) {
464
+ var db = client . db ( configuration . db ) ;
465
+ db . createCollection ( 'test_where' , function ( err , collection ) {
466
+ collection . insert (
467
+ [ { a : 1 } , { a : 2 } , { a : 3 } ] ,
468
+ configuration . writeConcernMax ( ) ,
469
+ function ( err ) {
470
+ expect ( err ) . to . not . exist ;
471
+ collection . count ( function ( err , count ) {
472
+ expect ( err ) . to . not . exist ;
473
+ test . equal ( 3 , count ) ;
474
+
475
+ // Let's test usage of the $where statement
476
+ collection . find ( { $where : new Code ( 'this.a > 2' ) } ) . count ( function ( err , count ) {
477
+ expect ( err ) . to . not . exist ;
478
+ test . equal ( 1 , count ) ;
479
+
480
+ collection
481
+ . find ( { $where : new Code ( 'this.a > i' , { i : 1 } ) } )
482
+ . count ( function ( err , count ) {
483
+ expect ( err ) . to . not . exist ;
484
+ test . equal ( 2 , count ) ;
485
+
486
+ // Let's close the db
487
+ client . close ( done ) ;
488
+ } ) ;
489
+ } ) ;
490
+ } ) ;
491
+ }
492
+ ) ;
493
+ } ) ;
494
+ } ) ;
495
+ }
496
+ } ) ;
497
+
453
498
it ( 'shouldCorrectlyPerformFindsWithHintTurnedOn' , {
454
499
metadata : {
455
500
requires : { topology : [ 'single' , 'replicaset' , 'sharded' , 'ssl' , 'heap' , 'wiredtiger' ] }
0 commit comments