diff options
author | Dwight <dmerriman@gmail.com> | 2008-06-02 20:27:45 -0400 |
---|---|---|
committer | Dwight <dmerriman@gmail.com> | 2008-06-02 20:27:45 -0400 |
commit | 9fba70e49f1ee1fb5be8c0fa02124784520d79d4 (patch) | |
tree | 1d370c924861d24020d8ebc14a63dbf0dfd0416b | |
parent | 36435d4e78fc839dafceb46a342b8c1c6b3abe22 (diff) | |
download | mongo-9fba70e49f1ee1fb5be8c0fa02124784520d79d4.tar.gz |
query embedded objects
-rw-r--r-- | db/db.cpp | 7 | ||||
-rw-r--r-- | db/jsobj.cpp | 98 | ||||
-rw-r--r-- | db/jsobj.h | 7 | ||||
-rw-r--r-- | db/namespace.h | 2 | ||||
-rw-r--r-- | db/pdfile.cpp | 10 | ||||
-rw-r--r-- | db/testdb.js | 678 |
6 files changed, 421 insertions, 381 deletions
diff --git a/db/db.cpp b/db/db.cpp index f8655b08353..eed9958981c 100644 --- a/db/db.cpp +++ b/db/db.cpp @@ -130,12 +130,11 @@ void receivedUpdate(Message& m, stringstream& ss) { ss << ns << ' ';
int flags = d.pullInt();
JSObj query = d.nextJsObj();
-cout << query.toString() << endl;
+
assert( d.moreJSObjs() );
assert( query.objsize() < m.data->dataLen() );
JSObj toupdate = d.nextJsObj();
-cout << toupdate.toString() << endl;
-cout << "TEMP " << flags << endl;
+
assert( toupdate.objsize() < m.data->dataLen() );
assert( query.objsize() + toupdate.objsize() < m.data->dataLen() );
updateObjects(ns, toupdate, query, flags & 1, ss);
@@ -275,7 +274,7 @@ public: };
void listen(int port) {
- const char *Version = "db version: 109 30apr2008 sai hack,keylen";
+ const char *Version = "db version: 110 2jun2008 embedded obj queries";
problem() << Version << endl;
cout << Version << endl;
pdfileInit();
diff --git a/db/jsobj.cpp b/db/jsobj.cpp index e600af83317..a45d0eb4570 100644 --- a/db/jsobj.cpp +++ b/db/jsobj.cpp @@ -409,56 +409,50 @@ bool JSMatcher::matches(JSObj& jsobj, bool *deep) { for( int r = 0; r < nRegex; r++ ) {
RegexMatcher& rm = regexs[r];
- JSElemIter k(jsobj);
- while( 1 ) {
- if( !k.more() )
- return false;
- Element e = k.next();
- if( strcmp(e.fieldName(), rm.fieldName) == 0 ) {
- char buf[64];
- const char *p = buf;
- if( e.type() == String )
- p = e.valuestr();
- else if( e.type() == Number ) {
- sprintf(buf, "%f", e.number());
- }
- else if( e.type() == Date ) {
- unsigned long long d = e.date();
- time_t t = (d/1000);
- time_t_to_String(t, buf);
- }
- else
- return false;
- if( !rm.re->PartialMatch(p) )
- return false;
- break;
+ Element e = jsobj.getFieldDotted(rm.fieldName);
+ if( e.eoo() )
+ return false;
+ {
+ char buf[64];
+ const char *p = buf;
+ if( e.type() == String )
+ p = e.valuestr();
+ else if( e.type() == Number ) {
+ sprintf(buf, "%f", e.number());
}
+ else if( e.type() == Date ) {
+ unsigned long long d = e.date();
+ time_t t = (d/1000);
+ time_t_to_String(t, buf);
+ }
+ else
+ return false;
+ if( !rm.re->PartialMatch(p) )
+ return false;
}
}
// check normal non-regex cases:
for( int i = 0; i < n; i++ ) {
Element& m = toMatch[i];
- JSElemIter k(jsobj);
- while( k.more() ) {
- Element e = k.next();
- if( strcmp(e.fieldName(), m.fieldName())== 0 ) {
- if( valuesMatch(e, m, compareOp[i]) ) {
- goto ok;
- }
- else if( e.type() == Array ) {
- JSElemIter ai(e.embeddedObject());
- while( ai.more() ) {
- Element z = ai.next();
- if( valuesMatch( z, m, compareOp[i]) ) {
- if( deep )
- *deep = true;
- goto ok;
- }
+
+ Element e = jsobj.getFieldDotted(m.fieldName());
+ if( !e.eoo() ) {
+ if( valuesMatch(e, m, compareOp[i]) ) {
+ goto ok;
+ }
+ else if( e.type() == Array ) {
+ JSElemIter ai(e.embeddedObject());
+ while( ai.more() ) {
+ Element z = ai.next();
+ if( valuesMatch( z, m, compareOp[i]) ) {
+ if( deep )
+ *deep = true;
+ goto ok;
}
}
- return false;
}
+ return false;
}
/* missing. that is ok iff we were looking for null */
@@ -543,6 +537,30 @@ int JSObj::woCompare(const JSObj& r) const { return -1;
}
+/* return has eoo() true if no match
+ supports "." notation to reach into embedded objects
+*/
+Element JSObj::getFieldDotted(const char *name) {
+ {
+ const char *p = strchr(name, '.');
+ if( p ) {
+ string left(name, p-name);
+ JSObj sub = getObjectField(left.c_str());
+ return sub.isEmpty() ? nullElement : sub.getFieldDotted(p+1);
+ }
+ }
+
+ JSElemIter i(*this);
+ while( i.more() ) {
+ Element e = i.next();
+ if( e.eoo() )
+ break;
+ if( strcmp(e.fieldName(), name) == 0 )
+ return e;
+ }
+ return nullElement;
+}
+
Element JSObj::getField(const char *name) {
JSElemIter i(*this);
while( i.more() ) {
diff --git a/db/jsobj.h b/db/jsobj.h index ff74d6e286d..cd00b0387d3 100644 --- a/db/jsobj.h +++ b/db/jsobj.h @@ -187,7 +187,13 @@ explicit int addFields(JSObj& from, set<string>& fields); /* returns n added */
int getFieldNames(set<string>& fields);
+ /* return has eoo() true if no match
+ supports "." notation to reach into embedded objects
+ */
+ Element getFieldDotted(const char *name);
+
Element getField(const char *name); /* return has eoo() true if no match */
+
const char * getStringField(const char *name);
JSObj getObjectField(const char *name);
@@ -410,6 +416,7 @@ public: ~JSMatcher();
+ /* deep means we looked into arrays for a match */
bool matches(JSObj& j, bool *deep = 0);
int getN() { return n; }
diff --git a/db/namespace.h b/db/namespace.h index 1d76695acb6..9107971b391 100644 --- a/db/namespace.h +++ b/db/namespace.h @@ -112,7 +112,7 @@ public: DiskLoc alloc(const char *ns, int lenToAlloc, DiskLoc& extentLoc);
void addDeletedRec(DeletedRecord *d, DiskLoc dloc);
private:
- DiskLoc __alloc(int len);
+ DiskLoc __stdAlloc(int len);
DiskLoc _alloc(const char *ns, int len);
void compact();
};
diff --git a/db/pdfile.cpp b/db/pdfile.cpp index f4da75775bf..2d6b872046e 100644 --- a/db/pdfile.cpp +++ b/db/pdfile.cpp @@ -109,8 +109,10 @@ DiskLoc NamespaceDetails::alloc(const char *ns, int lenToAlloc, DiskLoc& extentL return loc;
}
-/* returned item is out of the deleted list upon return */
-DiskLoc NamespaceDetails::__alloc(int len) {
+/* for non-capped collections.
+ returned item is out of the deleted list upon return
+*/
+DiskLoc NamespaceDetails::__stdAlloc(int len) {
DiskLoc *prev;
DiskLoc *bestprev = 0;
DiskLoc bestmatch;
@@ -217,7 +219,7 @@ void NamespaceDetails::compact() { DiskLoc NamespaceDetails::_alloc(const char *ns, int len) {
if( !capped )
- return __alloc(len);
+ return __stdAlloc(len);
assert( len < 400000000 );
int passes = 0;
@@ -226,7 +228,7 @@ DiskLoc NamespaceDetails::_alloc(const char *ns, int len) { // delete records until we have room and the max # objects limit achieved.
while( 1 ) {
if( nrecords < max ) {
- loc = __alloc(len);
+ loc = __stdAlloc(len);
if( !loc.isNull() )
break;
}
diff --git a/db/testdb.js b/db/testdb.js index 047fce5509b..3b7709c5650 100644 --- a/db/testdb.js +++ b/db/testdb.js @@ -1,248 +1,260 @@ -// testdb.js
-
-var fail = 0;
-
-var t = connect("test");
-db=t;
-
-core.db.db();
-
-var z = 0;
-function progress() {}// print(++z); }
-
-function failure(f, args) {
- print("FAIL: " + f + ' ' + (args.length<2?"":args[1]));
- fail++;
-}
-
-function assert(x) {
- if( !x )
- failure("assert", arguments);
-}
-
-function oneresult(c) {
- if( c.length() != 1 ) {
- failure("ERROR: wrong # of results: " + c.length(), arguments);
- }
-}
-
-function noresult(c) {
- if( c.length() != 0 )
- failure("ERROR: wrong # of results: " + c.length(), arguments);
-}
-
-function testkeys() {
- t.testkeys.save( { name: 5 } );
- t.testkeys.ensureIndex({name:true});
- t.testkeys.save( { name: 6 } );
- t.testkeys.save( { name: 8 } );
- t.testkeys.save( { name: 3 } );
- print("t.testkeys");
-}
-
-function testdelete() {
- print("testdelete");
- t.testkeys.remove({});
- testkeys();
- t.testkeys.remove({});
- testkeys();
- assert( t.testkeys.find().toArray().length == 4, "testkeys" );
-}
-
-function index2() {
- t.z.remove({});
- t.z.save( { a: -3 } );
- t.z.ensureIndex( { a:true} );
- for( var i = 0; i < 300; i++ )
- t.z.save( { a: i, b: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccdddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddfffffffffffffffffffffffffffffff" } );
- t.z.remove({});
-}
-
-function giantIndexTest() {
- print("giantIndexTest");
- drop("giant");
- db.giant.save({moe:1,foo:[33],bar:"aaaaa"});
-
- var z = 0;
- var prime = 127;
- for( var i = 0; i < 20000; i++ ) {
- var ar = [];
- for( var j = 0; j < 100; j++ ) {
- z += prime;
- ar.push( z % 100 );
- }
- db.giant.save({foo:ar, bar:"bbbbb"});
- if( i % 1000 == 0 ) print(i);
- if( i == 10000 )
- db.giant.ensureIndex({foo:1});
- }
-
-
- assert( db.giant.findOne({foo:33}) );
- print("giantIndexTest end");
-}
-
-function giant2() {
- print("giant2");
- drop("giant");
- db.giant.save({moe:1,foo:[33],bar:"aaaaa",q:-1});
-
- var z = 0;
- var prime = 127;
- for( var i = 0; i < 20000; i++ ) {
- var ar = [];
- for( var j = 0; j < 100; j++ ) {
- z += prime;
- ar.push( z % 100 );
- }
- db.giant.save({foo:ar, bar:"bbbbb", q:i});
- if( i % 1000 == 0 ) print(i);
- if( 0 && i == 10000 )
- db.giant.ensureIndex({foo:1});
- }
-
-
- assert( db.giant.findOne({foo:33}) );
- print("giant2 end");
-}
-
-// mx=-3;
-// db.giant.find().forEach( function(x) {
-// if( x.q % 100 == 0 ) print(x.q); if( x.q > mx ) { x.name = "john smith"; db.giant.save(x); mx = x.q; } } );} } );
-
-function bigIndexTest() {
- t.big.remove({});
- t.big.save( { name: "Dwight" } );
- t.big.ensureIndex({name: true});
- for( var i = 0; i < 1000; i++ ) {
- var x = { name: "e" + Math.random() + "abcdefasdflkjfdslkjdslkjfdslkjfdslkjfdslkjdflkj fdslkjfdslkjdsljfdslkjdsl fdslkfdslkjfdslkjlkjdsf fdslkjfds",
- addr: "1234 main", phone: 7 };
- t.big.save(x);
- }
- for( var i = 0; i < 1000; i++ ) {
- var x = { name: "c" + Math.random() + "abcdefasdflkjfdslkjdslkjfdslkjfdslkjfdslkjdflkj fdslkjfdslkjdsljfdslkjdsl fdslkfdslkjfdslkjlkjdsf fdslkjfds",
- addr: "1234 main", phone: 7 };
- t.big.save(x);
- }
-}
-
-function runall() {
- runcursors();
-
- runquick();
-
- print("bigindextest stuff:");
- t.big.remove( { } );
- bigIndexTest();
- t.big.find().sort({name:true});
- t.big.remove( { } );
- t.big.find().sort({name:true});
- bigIndexTest();
- t.big.find().sort({name:true});
- t.big.remove( { } );
-}
-
-function testarrayindexing() {
- print("testarrayindexing");
- t.ta.remove({});
- t.ta.save({name:"aaa", tags:["abc", "123", "foo"], z:1});
- t.ta.save({name:"baa", tags:["q", "123", 3], z:1});
- t.ta.save({name:"caa", tags:["dm", "123"], z:1});
- t.ta.save({name:"daa"});
-
- for( var pass=0; pass<=1; pass++ ) {
- oneresult( t.ta.find({tags:"foo"}) );
- oneresult( t.ta.find({tags:3}) );
- assert( t.ta.find({tags:"123"}).length() == 3 );
- t.ta.ensureIndex({tags:true});
- }
-}
-
-function testcapped(max) {
- print("testcapped");
- drop("capped");
-
- assert( createCollection("capped", { size: 4096, capped:true, max:max } ).ok );
-
- capped = db.capped;
- for(i=0; i<500; i++ ) {
- capped.save( { i: i, b: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxyyyyyyyyyyyyyyyyyyy" } );
- }
-
- var a = capped.find().toArray();
- assert( a.length < 100 );
- assert( a[a.length-1].i == 499 );
- assert( capped.find().sort({$natural:-1}).limit(1)[0].i == 499 );
- print("testcapped end");
-}
-
-function testgetmore() {
- print("testgetmore");
- drop("gm");
- gm=t.gm;
- for(i=0;i<50000;i++){
- gm.save({a:i, b:"adsffffffffffffffffffffffffffffffffffffffffffffffff\nfffffffffffffffffffffffffffffffffffffffffffffffffffff\nfffffffffffffffffffffffffffffffff"})
- }
- assert(gm.find().length()==50000);
-
- x = 0;
- c=gm.find();
- for(i=0;i<5000;i++) { x += c.next().a; }
-
- assert(gm.find().length()==50000); // full iteration with a cursor already live
- assert( gm.find()[10000].a == 10000 );
- assert( gm.find()[29000].a == 29000 );
- assert( gm.find()[9000].a == 9000 );
- d=gm.find();
- assert( d[20000].a==20000 );
- assert( d[10000].a==10000 );
- assert( d[40000].a==40000 );
- assert(gm.find().length()==50000); // full iteration with a cursor already live
-
- print( connect("intr").cursors.findOne().dump );
-
- print("testgetmore end");
-}
-
-function testdups() {
- print("testdups");
- K = 2000;
- for( pass=0;pass<1;pass++ ) {
- print(" pass:" + pass);
- if( pass < 2 ) {
- print("removing keys");
- t.td.remove({});
- }
- print("add keys");
- for( var x=0;x<K;x++ )
- t.td.save({ggg:"asdfasdf bbb a a jdssjsjdjds dsdsdsdsds d", z: x,
- str: "a long string dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd"});
- assert( t.td.find({ggg:"asdfasdf bbb a a jdssjsjdjds dsdsdsdsds d"}).toArray().length == K );
- // t.td.ensureIndex({ggg:true});
- if( pass == 0 )
- t.td.ensureIndex({ggg:1});
- // else if( pass == 1 )
- // t.td.ensureIndex({ggg:-1});
- }
- print(" end testdups");
- print(" try t.td.remove({});");
-}
-
-function testdups2() {
- print("testdups");
- for( pass=0;pass<1;pass++ ) {
- print(" pass:" + pass);
- t.td.remove({});
- for( var x=0;x<250;x++ )
- t.td.save({ggg:"asdfasdf bbb a a jdssjsjdjds dsdsdsdsds d", z: x,
- str: "a long string dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd"});
- assert( t.td.find({ggg:"asdfasdf bbb a a jdssjsjdjds dsdsdsdsds d"}).toArray().length == 2000 );
- t.td.ensureIndex({ggg:true});
- }
- t.td.remove({});
- print(" end testdups");
-}
-
+// testdb.js + +var fail = 0; + +var t = connect("test"); +db=t; + +core.db.db(); + +var z = 0; +function progress() {}// print(++z); } + +function failure(f, args) { + print("FAIL: " + f + ' ' + (args.length<2?"":args[1])); + fail++; +} + +function assert(x) { + if( !x ) + failure("assert", arguments); +} + +function oneresult(c) { + if( c.length() != 1 ) { + failure("ERROR: wrong # of results: " + c.length(), arguments); + } +} + +function noresult(c) { + if( c.length() != 0 ) + failure("ERROR: wrong # of results: " + c.length(), arguments); +} + +function testdots() { + t.dots.remove({}); + t.dots.save( { a: 3, b: { y: 4, z : 5 } } ); + oneresult( t.dots.find( { a:3 } ) ); + oneresult( t.dots.find( { b: { y:4,z:5} } ) ); + oneresult( t.dots.find( { a:3, b: { y:4,z:5} } ) ); + noresult( t.dots.find( { b: { y:4} } ) ); + oneresult( t.dots.find( { "b.y":4 } ) ); + oneresult( t.dots.find( { "b.z":5 } ) ); + noresult( t.dots.find( { "b.z":55 } ) ); +} + +function testkeys() { + t.testkeys.save( { name: 5 } ); + t.testkeys.ensureIndex({name:true}); + t.testkeys.save( { name: 6 } ); + t.testkeys.save( { name: 8 } ); + t.testkeys.save( { name: 3 } ); + print("t.testkeys"); +} + +function testdelete() { + print("testdelete"); + t.testkeys.remove({}); + testkeys(); + t.testkeys.remove({}); + testkeys(); + assert( t.testkeys.find().toArray().length == 4, "testkeys" ); +} + +function index2() { + t.z.remove({}); + t.z.save( { a: -3 } ); + t.z.ensureIndex( { a:true} ); + for( var i = 0; i < 300; i++ ) + t.z.save( { a: i, b: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccdddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddfffffffffffffffffffffffffffffff" } ); + t.z.remove({}); +} + +function giantIndexTest() { + print("giantIndexTest"); + drop("giant"); + db.giant.save({moe:1,foo:[33],bar:"aaaaa"}); + + var z = 0; + var prime = 127; + for( var i = 0; i < 20000; i++ ) { + var ar = []; + for( var j = 0; j < 100; j++ ) { + z += prime; + ar.push( z % 100 ); + } + db.giant.save({foo:ar, bar:"bbbbb"}); + if( i % 1000 == 0 ) print(i); + if( i == 10000 ) + db.giant.ensureIndex({foo:1}); + } + + + assert( db.giant.findOne({foo:33}) ); + print("giantIndexTest end"); +} + +function giant2() { + print("giant2"); + drop("giant"); + db.giant.save({moe:1,foo:[33],bar:"aaaaa",q:-1}); + + var z = 0; + var prime = 127; + for( var i = 0; i < 20000; i++ ) { + var ar = []; + for( var j = 0; j < 100; j++ ) { + z += prime; + ar.push( z % 100 ); + } + db.giant.save({foo:ar, bar:"bbbbb", q:i}); + if( i % 1000 == 0 ) print(i); + if( 0 && i == 10000 ) + db.giant.ensureIndex({foo:1}); + } + + + assert( db.giant.findOne({foo:33}) ); + print("giant2 end"); +} + +// mx=-3; +// db.giant.find().forEach( function(x) { +// if( x.q % 100 == 0 ) print(x.q); if( x.q > mx ) { x.name = "john smith"; db.giant.save(x); mx = x.q; } } );} } ); + +function bigIndexTest() { + t.big.remove({}); + t.big.save( { name: "Dwight" } ); + t.big.ensureIndex({name: true}); + for( var i = 0; i < 1000; i++ ) { + var x = { name: "e" + Math.random() + "abcdefasdflkjfdslkjdslkjfdslkjfdslkjfdslkjdflkj fdslkjfdslkjdsljfdslkjdsl fdslkfdslkjfdslkjlkjdsf fdslkjfds", + addr: "1234 main", phone: 7 }; + t.big.save(x); + } + for( var i = 0; i < 1000; i++ ) { + var x = { name: "c" + Math.random() + "abcdefasdflkjfdslkjdslkjfdslkjfdslkjfdslkjdflkj fdslkjfdslkjdsljfdslkjdsl fdslkfdslkjfdslkjlkjdsf fdslkjfds", + addr: "1234 main", phone: 7 }; + t.big.save(x); + } +} + +function runall() { + runcursors(); + + runquick(); + + print("bigindextest stuff:"); + t.big.remove( { } ); + bigIndexTest(); + t.big.find().sort({name:true}); + t.big.remove( { } ); + t.big.find().sort({name:true}); + bigIndexTest(); + t.big.find().sort({name:true}); + t.big.remove( { } ); +} + +function testarrayindexing() { + print("testarrayindexing"); + t.ta.remove({}); + t.ta.save({name:"aaa", tags:["abc", "123", "foo"], z:1}); + t.ta.save({name:"baa", tags:["q", "123", 3], z:1}); + t.ta.save({name:"caa", tags:["dm", "123"], z:1}); + t.ta.save({name:"daa"}); + + for( var pass=0; pass<=1; pass++ ) { + oneresult( t.ta.find({tags:"foo"}) ); + oneresult( t.ta.find({tags:3}) ); + assert( t.ta.find({tags:"123"}).length() == 3 ); + t.ta.ensureIndex({tags:true}); + } +} + +function testcapped(max) { + print("testcapped"); + drop("capped"); + + assert( createCollection("capped", { size: 4096, capped:true, max:max } ).ok ); + + capped = db.capped; + for(i=0; i<500; i++ ) { + capped.save( { i: i, b: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxyyyyyyyyyyyyyyyyyyy" } ); + } + + var a = capped.find().toArray(); + assert( a.length < 100 ); + assert( a[a.length-1].i == 499 ); + assert( capped.find().sort({$natural:-1}).limit(1)[0].i == 499 ); + print("testcapped end"); +} + +function testgetmore() { + print("testgetmore"); + drop("gm"); + gm=t.gm; + for(i=0;i<50000;i++){ + gm.save({a:i, b:"adsffffffffffffffffffffffffffffffffffffffffffffffff\nfffffffffffffffffffffffffffffffffffffffffffffffffffff\nfffffffffffffffffffffffffffffffff"}) + } + assert(gm.find().length()==50000); + + x = 0; + c=gm.find(); + for(i=0;i<5000;i++) { x += c.next().a; } + + assert(gm.find().length()==50000); // full iteration with a cursor already live + assert( gm.find()[10000].a == 10000 ); + assert( gm.find()[29000].a == 29000 ); + assert( gm.find()[9000].a == 9000 ); + d=gm.find(); + assert( d[20000].a==20000 ); + assert( d[10000].a==10000 ); + assert( d[40000].a==40000 ); + assert(gm.find().length()==50000); // full iteration with a cursor already live + + print( connect("intr").cursors.findOne().dump ); + + print("testgetmore end"); +} + +function testdups() { + print("testdups"); + K = 2000; + for( pass=0;pass<1;pass++ ) { + print(" pass:" + pass); + if( pass < 2 ) { + print("removing keys"); + t.td.remove({}); + } + print("add keys"); + for( var x=0;x<K;x++ ) + t.td.save({ggg:"asdfasdf bbb a a jdssjsjdjds dsdsdsdsds d", z: x, + str: "a long string dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd"}); + assert( t.td.find({ggg:"asdfasdf bbb a a jdssjsjdjds dsdsdsdsds d"}).toArray().length == K ); + // t.td.ensureIndex({ggg:true}); + if( pass == 0 ) + t.td.ensureIndex({ggg:1}); + // else if( pass == 1 ) + // t.td.ensureIndex({ggg:-1}); + } + print(" end testdups"); + print(" try t.td.remove({});"); +} + +function testdups2() { + print("testdups"); + for( pass=0;pass<1;pass++ ) { + print(" pass:" + pass); + t.td.remove({}); + for( var x=0;x<250;x++ ) + t.td.save({ggg:"asdfasdf bbb a a jdssjsjdjds dsdsdsdsds d", z: x, + str: "a long string dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd"}); + assert( t.td.find({ggg:"asdfasdf bbb a a jdssjsjdjds dsdsdsdsds d"}).toArray().length == 2000 ); + t.td.ensureIndex({ggg:true}); + } + t.td.remove({}); + print(" end testdups"); +} + /* * tests UTF-8 in the regexp package in the db : save a string w/ two unicode characters @@ -256,93 +268,95 @@ function test_utf8() { db.utf.remove({}); } -function runcursors() {
- print("initial remove");
- t.cur.remove({});
- t.cur.findOne();
- print(" done");
-
- print( tojson( connect("intr").cursors.find() ) );
-
- print("insert");
-
- for( i = 0; i < 50000; i++ )
- t.cur.save( { name:"ABC", k:/asfd/, a:i,
- lng:"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
- lng1:"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
- lng2:"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"} );
-
- for( i = 0; i < 100; i++ ) {
- c = t.cur.find().limit(2);
- print(c[0].name);
- t.cur.find({name:"ABC"}).limit(3)[0];
- }
-
- print( tojson( connect("intr").cursors.find() ) );
-
- print("Remove...");
- t.cur.remove({});
- t.cur.findOne();
- print(" done");
-
- print( tojson( connect("intr").cursors.find() ) );
-
- print(" end runcursors");
-}
-
-function runquick() {
- print("runquick");
- start = Date();
-
- testcapped();
-
- testgetmore();
-
- t.nullcheck.remove({});
- t.nullcheck.save( { a : 3 } );
- oneresult( t.nullcheck.find() );
-
- /* todo uncomment when eliot fixes! */
- assert( t.nullcheck.find({a:3})[0].a == 3, "a3" );
- oneresult( t.nullcheck.find( { b: null } ) ); progress();
- noresult( t.nullcheck.find( { b: 1 } ) ); progress();
- oneresult( t.nullcheck.find( { a : "3" } ), "todo num to str match" ); progress();
-
- // regex
- print("regex");
- t.reg.remove({});
- t.reg.save( { name: "Dwight", a : 345, dt: Date() } );
- for( i = 0; i < 2; i++ ) {
- oneresult( t.reg.find( { name: /Dwi./ } ), "re1" );
- oneresult( t.reg.find( { dt: /20/ } ), "date regexp match" );
- oneresult( t.reg.find( { a: /34/ } ), "regexp match number" );
- noresult( t.reg.find( { name: /dwi./ } ), "re2" );
- oneresult( t.reg.find( { name: /dwi/i } ), "re3" );
- t.reg.ensureIndex( { name: true } );
- }
-
- testdelete();
-
- testarrayindexing();
-
- runcursors();
+function runcursors() { + print("initial remove"); + t.cur.remove({}); + t.cur.findOne(); + print(" done"); + + print( tojson( connect("intr").cursors.find() ) ); + + print("insert"); + + for( i = 0; i < 50000; i++ ) + t.cur.save( { name:"ABC", k:/asfd/, a:i, + lng:"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + lng1:"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + lng2:"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"} ); + + for( i = 0; i < 100; i++ ) { + c = t.cur.find().limit(2); + print(c[0].name); + t.cur.find({name:"ABC"}).limit(3)[0]; + } + + print( tojson( connect("intr").cursors.find() ) ); + + print("Remove..."); + t.cur.remove({}); + t.cur.findOne(); + print(" done"); + + print( tojson( connect("intr").cursors.find() ) ); + + print(" end runcursors"); +} + +function runquick() { + print("runquick"); + start = Date(); + + testdots(); + + testcapped(); + + testgetmore(); + + t.nullcheck.remove({}); + t.nullcheck.save( { a : 3 } ); + oneresult( t.nullcheck.find() ); + + /* todo uncomment when eliot fixes! */ + assert( t.nullcheck.find({a:3})[0].a == 3, "a3" ); + oneresult( t.nullcheck.find( { b: null } ) ); progress(); + noresult( t.nullcheck.find( { b: 1 } ) ); progress(); + oneresult( t.nullcheck.find( { a : "3" } ), "todo num to str match" ); progress(); + + // regex + print("regex"); + t.reg.remove({}); + t.reg.save( { name: "Dwight", a : 345, dt: Date() } ); + for( i = 0; i < 2; i++ ) { + oneresult( t.reg.find( { name: /Dwi./ } ), "re1" ); + oneresult( t.reg.find( { dt: /20/ } ), "date regexp match" ); + oneresult( t.reg.find( { a: /34/ } ), "regexp match number" ); + noresult( t.reg.find( { name: /dwi./ } ), "re2" ); + oneresult( t.reg.find( { name: /dwi/i } ), "re3" ); + t.reg.ensureIndex( { name: true } ); + } + + testdelete(); + + testarrayindexing(); + + runcursors(); print("Testing UTF-8 support in db regex"); test_utf8(); -
- print("testdups last to go, it takes a little time...");
- testdups();
-
- print("runquick done");
- print("start: " + start);
- print("finish: " + Date());
-}
-
-print("testdb.js: try runall()");
-print(" runquick()");
-print(" bigIndexTest()");
-print(" giantindexTest()");
-print(" runcursors()");
-print(" testgetmore()");
-print(" testcapped()");
-
+ + print("testdups last to go, it takes a little time..."); + testdups(); + + print("runquick done"); + print("start: " + start); + print("finish: " + Date()); +} + +print("testdb.js: try runall()"); +print(" runquick()"); +print(" bigIndexTest()"); +print(" giantindexTest()"); +print(" runcursors()"); +print(" testgetmore()"); +print(" testcapped()"); + |