summaryrefslogtreecommitdiff
path: root/jstests/sort_numeric.js
blob: 807f23dfe8db5a37b2641fabee5b99f3cc1285bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35

t = db.sort_numeric;
t.drop();

// there are two numeric types int he db; make sure it handles them right
// for comparisons.

t.save( { a : 3 } );
t.save( { a : 3.1 } );
t.save( { a : 2.9 } );
t.save( { a : 1 } );
t.save( { a : 1.9 } );
t.save( { a : 5 } );
t.save( { a : 4.9 } );
t.save( { a : 2.91 } );

for( var pass = 0; pass < 2; pass++ ) { 

    var c = t.find().sort({a:1});
    var last = 0;
    while( c.hasNext() ) {
        current = c.next();
	assert( current.a > last );
        last = current.a;
    }

    assert( t.find({a:3}).count() == 1 );
    assert( t.find({a:3.0}).count() == 1 );
    assert( t.find({a:3.0}).length() == 1 );

    t.ensureIndex({a:1});
}

assert(t.validate().valid);