0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-12-01 09:32:32 +01:00
mongodb/jstests/find1.js

31 lines
1.1 KiB
JavaScript
Raw Normal View History

2009-01-27 05:28:26 +01:00
t = db.find1;
t.drop();
t.save( { a : 1 , b : "hi" } );
t.save( { a : 2 , b : "hi" } );
2009-08-09 18:13:50 +02:00
/* very basic test of $snapshot just that we get some result */
// we are assumign here that snapshot uses the id index; maybe one day it doesn't if so this would need to change then
assert( t.find({$query:{},$snapshot:1})[0].a == 1 , "$snapshot simple test 1" );
var q = t.findOne();
q.c = "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz";
t.save(q); // will move a:1 object to after a:2 in the file
assert( t.find({$query:{},$snapshot:1})[0].a == 1 , "$snapshot simple test 2" );
2009-01-27 05:28:26 +01:00
assert( t.findOne( { a : 1 } ).b != null , "A" );
assert( t.findOne( { a : 1 } , { a : 1 } ).b == null , "B");
assert( t.find( { a : 1 } )[0].b != null , "C" );
assert( t.find( { a : 1 } , { a : 1 } )[0].b == null , "D" );
id = t.findOne()._id;
assert( t.findOne( id ) , "E" );
assert( t.findOne( id ).a , "F" );
assert( t.findOne( id ).b , "G" );
assert( t.findOne( id , { a : 1 } ).a , "H" );
assert( ! t.findOne( id , { a : 1 } ).b , "I" );
2009-01-27 05:28:26 +01:00
assert(t.validate().valid,"not valid");