~ubuntu-branches/ubuntu/trusty/mongodb/trusty-proposed

« back to all changes in this revision

Viewing changes to jstests/apitest_dbcollection.js

  • Committer: Bazaar Package Importer
  • Author(s): Antonin Kral
  • Date: 2010-01-29 19:48:45 UTC
  • Revision ID: james.westby@ubuntu.com-20100129194845-8wbmkf626fwcavc9
Tags: upstream-1.3.1
ImportĀ upstreamĀ versionĀ 1.3.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 *   Tests for the db collection 
 
3
 */
 
4
 
 
5
 
 
6
 
 
7
/*
 
8
 *  test drop
 
9
 */
 
10
db.getCollection( "test_db" ).drop();
 
11
assert(db.getCollection( "test_db" ).find().length() == 0,1);
 
12
 
 
13
db.getCollection( "test_db" ).save({a:1});
 
14
assert(db.getCollection( "test_db" ).find().length() == 1,2);
 
15
 
 
16
db.getCollection( "test_db" ).drop();
 
17
assert(db.getCollection( "test_db" ).find().length() == 0,3);
 
18
 
 
19
/*
 
20
 * test count
 
21
 */
 
22
 
 
23
assert(db.getCollection( "test_db" ).count() == 0,4);
 
24
db.getCollection( "test_db" ).save({a:1});
 
25
assert(db.getCollection( "test_db" ).count() == 1,5);
 
26
for (i = 0; i < 100; i++) {
 
27
    db.getCollection( "test_db" ).save({a:1});
 
28
}
 
29
assert(db.getCollection( "test_db" ).count() == 101,6);
 
30
db.getCollection( "test_db" ).drop();
 
31
assert(db.getCollection( "test_db" ).count() == 0,7);
 
32
 
 
33
/*
 
34
 *  test clean (not sure... just be sure it doen't blow up, I guess
 
35
 */ 
 
36
 
 
37
 db.getCollection( "test_db" ).clean();
 
38
 
 
39
 /*
 
40
  * test validate
 
41
  */
 
42
 
 
43
db.getCollection( "test_db" ).drop();
 
44
assert(db.getCollection( "test_db" ).count() == 0,8);
 
45
 
 
46
for (i = 0; i < 100; i++) {
 
47
    db.getCollection( "test_db" ).save({a:1});
 
48
}
 
49
  
 
50
var v = db.getCollection( "test_db" ).validate();
 
51
if( v.ns != "test.test_db" ) { 
 
52
    print("Error: wrong ns name");
 
53
    print(tojson(v));
 
54
}
 
55
assert (v.ns == "test.test_db",9);
 
56
assert (v.ok == 1,10);
 
57
 
 
58
assert(v.result.toString().match(/nrecords\?:(\d+)/)[1] == 100,11);
 
59
 
 
60
/*
 
61
 * test deleteIndex, deleteIndexes
 
62
 */
 
63
 
 
64
db.getCollection( "test_db" ).drop();
 
65
assert(db.getCollection( "test_db" ).count() == 0,12);
 
66
db.getCollection( "test_db" ).dropIndexes();
 
67
assert(db.getCollection( "test_db" ).getIndexes().length == 0,13);  
 
68
 
 
69
db.getCollection( "test_db" ).save({a:10});
 
70
assert(db.getCollection( "test_db" ).getIndexes().length == 1,14);  
 
71
 
 
72
db.getCollection( "test_db" ).ensureIndex({a:1});
 
73
db.getCollection( "test_db" ).save({a:10});
 
74
 
 
75
print( tojson( db.getCollection( "test_db" ).getIndexes() ) );
 
76
assert.eq(db.getCollection( "test_db" ).getIndexes().length , 2,15);  
 
77
 
 
78
db.getCollection( "test_db" ).dropIndex({a:1});
 
79
assert(db.getCollection( "test_db" ).getIndexes().length == 1,16);  
 
80
 
 
81
db.getCollection( "test_db" ).save({a:10});
 
82
db.getCollection( "test_db" ).ensureIndex({a:1});
 
83
db.getCollection( "test_db" ).save({a:10});
 
84
 
 
85
assert(db.getCollection( "test_db" ).getIndexes().length == 2,17);  
 
86
 
 
87
db.getCollection( "test_db" ).dropIndex("a_1");
 
88
assert.eq( db.getCollection( "test_db" ).getIndexes().length , 1,18);  
 
89
 
 
90
db.getCollection( "test_db" ).save({a:10, b:11});
 
91
db.getCollection( "test_db" ).ensureIndex({a:1});
 
92
db.getCollection( "test_db" ).ensureIndex({b:1});
 
93
db.getCollection( "test_db" ).save({a:10, b:12});
 
94
 
 
95
assert(db.getCollection( "test_db" ).getIndexes().length == 3,19);  
 
96
 
 
97
db.getCollection( "test_db" ).dropIndex({b:1});
 
98
assert(db.getCollection( "test_db" ).getIndexes().length == 2,20);  
 
99
db.getCollection( "test_db" ).dropIndex({a:1});
 
100
assert(db.getCollection( "test_db" ).getIndexes().length == 1,21);  
 
101
 
 
102
db.getCollection( "test_db" ).save({a:10, b:11});
 
103
db.getCollection( "test_db" ).ensureIndex({a:1});
 
104
db.getCollection( "test_db" ).ensureIndex({b:1});
 
105
db.getCollection( "test_db" ).save({a:10, b:12});
 
106
 
 
107
assert(db.getCollection( "test_db" ).getIndexes().length == 3,22);  
 
108
 
 
109
db.getCollection( "test_db" ).dropIndexes();
 
110
assert(db.getCollection( "test_db" ).getIndexes().length == 1,23);  
 
111
 
 
112
db.getCollection( "test_db" ).find();
 
113
 
 
114
db.getCollection( "test_db" ).drop();
 
115
assert(db.getCollection( "test_db" ).getIndexes().length == 0,24);