2009-01-26 23:23:45 +01:00
|
|
|
|
2010-01-05 19:48:26 +01:00
|
|
|
t = db.jstests_uniqueness;
|
2009-01-26 23:23:45 +01:00
|
|
|
|
|
|
|
t.drop();
|
|
|
|
|
|
|
|
// test uniqueness of _id
|
|
|
|
|
|
|
|
t.save( { _id : 3 } );
|
|
|
|
assert( !db.getLastError(), 1 );
|
|
|
|
|
|
|
|
// this should yield an error
|
|
|
|
t.insert( { _id : 3 } );
|
|
|
|
assert( db.getLastError() , 2);
|
|
|
|
assert( t.count() == 1, "hmmm");
|
|
|
|
|
|
|
|
t.insert( { _id : 4, x : 99 } );
|
|
|
|
assert( !db.getLastError() , 3);
|
|
|
|
|
|
|
|
// this should yield an error
|
|
|
|
t.update( { _id : 4 } , { _id : 3, x : 99 } );
|
|
|
|
assert( db.getLastError() , 4);
|
|
|
|
assert( t.findOne( {_id:4} ), 5 );
|
|
|
|
|
2009-06-19 19:26:58 +02:00
|
|
|
// Check for an error message when we index and there are dups
|
2010-01-12 20:55:51 +01:00
|
|
|
db.jstests_uniqueness2.drop();
|
|
|
|
db.jstests_uniqueness2.insert({a:3});
|
|
|
|
db.jstests_uniqueness2.insert({a:3});
|
|
|
|
assert( db.jstests_uniqueness2.count() == 2 , 6) ;
|
|
|
|
db.jstests_uniqueness2.ensureIndex({a:1}, true);
|
2009-01-26 23:23:45 +01:00
|
|
|
assert( db.getLastError() , 7);
|
2009-06-19 19:26:58 +02:00
|
|
|
|
|
|
|
/* Check that if we update and remove _id, it gets added back by the DB */
|
|
|
|
|
2009-06-19 22:03:44 +02:00
|
|
|
/* - test when object grows */
|
2009-06-19 19:26:58 +02:00
|
|
|
t.drop();
|
|
|
|
t.save( { _id : 'Z' } );
|
|
|
|
t.update( {}, { k : 2 } );
|
|
|
|
assert( t.findOne()._id == 'Z', "uniqueness.js problem with adding back _id" );
|
|
|
|
|
2009-06-19 22:03:44 +02:00
|
|
|
/* - test when doesn't grow */
|
2009-06-19 19:26:58 +02:00
|
|
|
t.drop();
|
|
|
|
t.save( { _id : 'Z', k : 3 } );
|
|
|
|
t.update( {}, { k : 2 } );
|
|
|
|
assert( t.findOne()._id == 'Z', "uniqueness.js problem with adding back _id (2)" );
|
|
|
|
|