File: sorta.js

package info (click to toggle)
mongodb 1%3A2.4.10-5
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 82,464 kB
  • sloc: cpp: 740,225; ansic: 152,098; sh: 13,820; python: 11,864; makefile: 1,012; perl: 922; pascal: 617; java: 452; lisp: 222; asm: 174
file content (26 lines) | stat: -rw-r--r-- 660 bytes parent folder | download | duplicates (4)
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
// SERVER-2905 sorting with missing fields

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

// Enable _allow_dot to try and bypass v8 field name checking.
t.insert( {_id:0,a:MinKey}, true );
t.save( {_id:3,a:null} );
t.save( {_id:1,a:[]} );
t.save( {_id:7,a:[2]} );
t.save( {_id:4} );
t.save( {_id:5,a:null} );
t.save( {_id:2,a:[]} );
t.save( {_id:6,a:1} );
t.insert( {_id:8,a:MaxKey}, true );

function sorted( arr ) {
    assert.eq( 9, arr.length );
 	for( i = 1; i < arr.length; ++i ) {
     	assert.lte( arr[ i-1 ]._id, arr[ i ]._id );
    }
}

sorted( t.find().sort( {a:1} ).toArray() );
t.ensureIndex( {a:1} );
sorted( t.find().sort( {a:1} ).hint( {a:1} ).toArray() );