0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-11-30 17:10:48 +01:00
mongodb/jstests/eval9.js

20 lines
663 B
JavaScript

a = [ 1 , "asd" , null , [ 2 , 3 ] , new Date() , { x : 1 } ]
for ( var i=0; i<a.length; i++ ){
var ret = db.eval( "function( a , i ){ return a[i]; }" , a , i );
assert.eq( typeof( a[i] ) , typeof( ret ) , "type test" );
assert.eq( a[i] , ret , "val test: " + typeof( a[i] ) );
}
db.eval9.drop();
db.eval9.save( { a : 17 } );
assert.eq( 1 , db.eval( "return db.eval9.find().toArray()" ).length , "A" );
assert.eq( 17 , db.eval( "return db.eval9.find().toArray()" )[0].a , "B" );
// just to make sure these things don't crash
assert( db.eval( "return db.eval9.find()" ) );
assert( db.eval( "return db.eval9" ) );
assert( db.eval( "return db" ) );