diff options
author | Dwight <dmerriman@gmail.com> | 2009-01-26 17:23:45 -0500 |
---|---|---|
committer | Dwight <dmerriman@gmail.com> | 2009-01-26 17:23:45 -0500 |
commit | c85b113c662b084330dd8d9ca8d15ba96f09f53c (patch) | |
tree | b789006966cc9d7766eb9ff806eda6edc5b07902 /jstests | |
parent | 92e897a62a6baa0ff25749831fbb94ef563eab41 (diff) | |
download | mongo-c85b113c662b084330dd8d9ca8d15ba96f09f53c.tar.gz |
check that _id is unique
Diffstat (limited to 'jstests')
-rw-r--r-- | jstests/uniqueness.js | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/jstests/uniqueness.js b/jstests/uniqueness.js new file mode 100644 index 00000000000..6cda7df2bbe --- /dev/null +++ b/jstests/uniqueness.js @@ -0,0 +1,33 @@ +//db=connect("192.168.58.1/test", u , p); + +t = db.foo; + +t.drop(); + +// test uniqueness of _id + +t.ensureIndex({_id:1}); + +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 ); + +/* Check for an error message when we index and there are dups */ +db.bar.drop(); +db.bar.insert({_id:3}); +db.bar.insert({_id:3}); +assert( db.bar.count() == 2 , 6) ; +db.bar.ensureIndex({_id:1}); +assert( db.getLastError() , 7); |