summaryrefslogtreecommitdiff
path: root/jstests/unique2.js
diff options
context:
space:
mode:
authorDwight <dmerriman@gmail.com>2009-09-21 16:31:00 -0400
committerDwight <dmerriman@gmail.com>2009-09-21 16:31:00 -0400
commit6bbaf0fdc3a1cba0be4862b2169535f8b2f113a9 (patch)
tree3c71a7e9d887066b5a42ed082868290634a82363 /jstests/unique2.js
parentd30ce5418dc205e427fd209b1d285b0e4808de2a (diff)
downloadmongo-6bbaf0fdc3a1cba0be4862b2169535f8b2f113a9.tar.gz
better unit tests for unique indexes and dropDup : true on indexing
Diffstat (limited to 'jstests/unique2.js')
-rw-r--r--jstests/unique2.js41
1 files changed, 41 insertions, 0 deletions
diff --git a/jstests/unique2.js b/jstests/unique2.js
new file mode 100644
index 00000000000..88f3a67bec9
--- /dev/null
+++ b/jstests/unique2.js
@@ -0,0 +1,41 @@
+
+t = db.foo;
+
+t.drop();
+
+/* test for good behavior when indexing multikeys */
+
+t.insert({k:3});
+t.insert({k:[2,3]});
+t.insert({k:[4,3]});
+
+t.ensureIndex({k:1}, {unique:true, dropDups:true});
+
+assert( t.count() == 1 ) ;
+assert( t.find().sort({k:1}).toArray().length == 1 ) ;
+assert( t.find().sort({k:1}).count() == 1 ) ;
+
+t.drop();
+
+t.ensureIndex({k:1}, {unique:true});
+
+t.insert({k:3});
+t.insert({k:[2,3]});
+t.insert({k:[4,3]});
+
+assert( t.count() == 1 ) ;
+assert( t.find().sort({k:1}).toArray().length == 1 ) ;
+assert( t.find().sort({k:1}).count() == 1 ) ;
+
+t.dropIndexes();
+
+t.insert({k:[2,3]});
+t.insert({k:[4,3]});
+assert( t.count() == 3 ) ;
+
+t.ensureIndex({k:1}, {unique:true, dropDups:true});
+
+assert( t.count() == 1 ) ;
+assert( t.find().sort({k:1}).toArray().length == 1 ) ;
+assert( t.find().sort({k:1}).count() == 1 ) ;
+