diff options
author | Eliot Horowitz <eliot@10gen.com> | 2009-01-26 23:28:26 -0500 |
---|---|---|
committer | Eliot Horowitz <eliot@10gen.com> | 2009-01-26 23:28:26 -0500 |
commit | bc38646deb39f5d5af3cd33e34f49b596e837401 (patch) | |
tree | 33affd5a1fedb7f8cfad044d92c262d12158ff8b /jstests/apitest_dbcollection.js | |
parent | f235a0f1b1a8ad6fbbce046205d4b78e60bc1df8 (diff) | |
download | mongo-bc38646deb39f5d5af3cd33e34f49b596e837401.tar.gz |
imported tests
Diffstat (limited to 'jstests/apitest_dbcollection.js')
-rw-r--r-- | jstests/apitest_dbcollection.js | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/jstests/apitest_dbcollection.js b/jstests/apitest_dbcollection.js new file mode 100644 index 00000000000..312c4e7f493 --- /dev/null +++ b/jstests/apitest_dbcollection.js @@ -0,0 +1,106 @@ +/** + * Tests for the db collection + */ + +db = connect( "test" ) + + +/* + * test drop + */ +db.getCollection( "test_db" ).drop(); +assert(db.getCollection( "test_db" ).find().length() == 0); + +db.getCollection( "test_db" ).save({a:1}); +assert(db.getCollection( "test_db" ).find().length() == 1); + +db.getCollection( "test_db" ).drop(); +assert(db.getCollection( "test_db" ).find().length() == 0); + +/* + * test count + */ + +assert(db.getCollection( "test_db" ).count() == 0); +db.getCollection( "test_db" ).save({a:1}); +assert(db.getCollection( "test_db" ).count() == 1); +for (i = 0; i < 100; i++) { + db.getCollection( "test_db" ).save({a:1}); +} +assert(db.getCollection( "test_db" ).count() == 101); +db.getCollection( "test_db" ).drop(); +assert(db.getCollection( "test_db" ).count() == 0); + +/* + * test clean (not sure... just be sure it doen't blow up, I guess + */ + + db.getCollection( "test_db" ).clean(); + + /* + * test validate + */ + +db.getCollection( "test_db" ).drop(); +assert(db.getCollection( "test_db" ).count() == 0); + +for (i = 0; i < 100; i++) { + db.getCollection( "test_db" ).save({a:1}); +} + +var v = db.getCollection( "test_db" ).validate(); +assert (v.ns == "test.test_db"); +assert (v.ok == 1); + +assert(v.result.toString().match(/nrecords\?:(\d+)/)[1] == 100); + +/* + * test deleteIndex, deleteIndexes + */ + +db.getCollection( "test_db" ).drop(); +assert(db.getCollection( "test_db" ).count() == 0); +db.getCollection( "test_db" ).dropIndexes(); +assert(db.getCollection( "test_db" ).getIndexes().length() == 0); + +db.getCollection( "test_db" ).save({a:10}); +db.getCollection( "test_db" ).ensureIndex({a:1}); +db.getCollection( "test_db" ).save({a:10}); + +assert(db.getCollection( "test_db" ).getIndexes().length() == 1); + +db.getCollection( "test_db" ).dropIndex({a:1}); +assert(db.getCollection( "test_db" ).getIndexes().length() == 0); + +db.getCollection( "test_db" ).save({a:10}); +db.getCollection( "test_db" ).ensureIndex({a:1}); +db.getCollection( "test_db" ).save({a:10}); + +assert(db.getCollection( "test_db" ).getIndexes().length() == 1); + +db.getCollection( "test_db" ).dropIndex("a_1"); +assert(db.getCollection( "test_db" ).getIndexes().length() == 0); + +db.getCollection( "test_db" ).save({a:10, b:11}); +db.getCollection( "test_db" ).ensureIndex({a:1}); +db.getCollection( "test_db" ).ensureIndex({b:1}); +db.getCollection( "test_db" ).save({a:10, b:12}); + +assert(db.getCollection( "test_db" ).getIndexes().length() == 2); + +db.getCollection( "test_db" ).dropIndex({b:1}); +assert(db.getCollection( "test_db" ).getIndexes().length() == 1); +db.getCollection( "test_db" ).dropIndex({a:1}); +assert(db.getCollection( "test_db" ).getIndexes().length() == 0); + +db.getCollection( "test_db" ).save({a:10, b:11}); +db.getCollection( "test_db" ).ensureIndex({a:1}); +db.getCollection( "test_db" ).ensureIndex({b:1}); +db.getCollection( "test_db" ).save({a:10, b:12}); + +assert(db.getCollection( "test_db" ).getIndexes().length() == 2); + +db.getCollection( "test_db" ).dropIndexes(); +assert(db.getCollection( "test_db" ).getIndexes().length() == 0); + +db.getCollection( "test_db" ).find(); |