summaryrefslogtreecommitdiff
path: root/client/examples
diff options
context:
space:
mode:
authorAntonin Kral <a.kral@bobek.cz>2010-08-11 12:38:57 +0200
committerAntonin Kral <a.kral@bobek.cz>2010-08-11 12:38:57 +0200
commit7645618fd3914cb8a20561625913c20d49504a49 (patch)
tree8370f846f58f6d71165b7a0e2eda04648584ec76 /client/examples
parent68c73c3c7608b4c87f07440dc3232801720b1168 (diff)
downloadmongodb-7645618fd3914cb8a20561625913c20d49504a49.tar.gz
Imported Upstream version 1.6.0
Diffstat (limited to 'client/examples')
-rw-r--r--client/examples/clientTest.cpp21
-rw-r--r--client/examples/tail.cpp35
2 files changed, 26 insertions, 30 deletions
diff --git a/client/examples/clientTest.cpp b/client/examples/clientTest.cpp
index bbb82f6..83a556a 100644
--- a/client/examples/clientTest.cpp
+++ b/client/examples/clientTest.cpp
@@ -137,10 +137,14 @@ int main( int argc, const char **argv ) {
assert( conn.getLastError() == "" );
// nonexistent index test
- assert( conn.findOne(ns, Query("{name:\"eliot\"}").hint("{foo:1}")).hasElement("$err") );
- assert( conn.getLastError() == "bad hint" );
- conn.resetError();
- assert( conn.getLastError() == "" );
+ bool asserted = false;
+ try {
+ conn.findOne(ns, Query("{name:\"eliot\"}").hint("{foo:1}"));
+ }
+ catch ( ... ){
+ asserted = true;
+ }
+ assert( asserted );
//existing index
assert( conn.findOne(ns, Query("{name:'eliot'}").hint("{name:1}")).hasElement("name") );
@@ -176,8 +180,9 @@ int main( int argc, const char **argv ) {
}
BSONObj found = conn.findOne( tsns , mongo::BSONObj() );
+ cout << "old: " << out << "\nnew: " << found << endl;
assert( ( oldTime < found["ts"].timestampTime() ) ||
- ( oldInc + 1 == found["ts"].timestampInc() ) );
+ ( oldTime == found["ts"].timestampTime() && oldInc < found["ts"].timestampInc() ) );
}
@@ -185,9 +190,9 @@ int main( int argc, const char **argv ) {
assert( conn.getLastError().empty() );
BufBuilder b;
- b.append( (int)0 ); // reserved
- b.append( (int)-1 ); // invalid # of cursors triggers exception
- b.append( (int)-1 ); // bogus cursor id
+ b.appendNum( (int)0 ); // reserved
+ b.appendNum( (int)-1 ); // invalid # of cursors triggers exception
+ b.appendNum( (int)-1 ); // bogus cursor id
Message m;
m.setData( dbKillCursors, b.buf(), b.len() );
diff --git a/client/examples/tail.cpp b/client/examples/tail.cpp
index e844b32..3738b4f 100644
--- a/client/examples/tail.cpp
+++ b/client/examples/tail.cpp
@@ -22,34 +22,25 @@
using namespace mongo;
-void foo() { }
+void tail(DBClientBase& conn, const char *ns) {
+ BSONElement lastId = minKey.firstElement();
+ Query query = Query();
-/* "tail" the specified namespace, outputting elements as they are added.
- _id values must be inserted in increasing order for this to work. (Some other
- field could also be used.)
+ auto_ptr<DBClientCursor> c =
+ conn.query(ns, query, 0, 0, 0, QueryOption_CursorTailable);
- Note: one could use a capped collection and $natural order to do something
- similar, using sort({$natural:1}), and then not need to worry about
- _id's being in order.
-*/
-void tail(DBClientBase& conn, const char *ns) {
- conn.ensureIndex(ns, fromjson("{_id:1}"));
- BSONElement lastId;
- Query query = Query().sort("_id");
while( 1 ) {
- auto_ptr<DBClientCursor> c = conn.query(ns, query, 0, 0, 0, Option_CursorTailable);
- while( 1 ) {
- if( !c->more() ) {
- if( c->isDead() ) {
- // we need to requery
- break;
- }
- sleepsecs(1);
+ if( !c->more() ) {
+ if( c->isDead() ) {
+ break; // we need to requery
+ }
+
+ // all data (so far) exhausted, wait for more
+ sleepsecs(1);
+ continue;
}
BSONObj o = c->next();
lastId = o["_id"];
cout << o.toString() << endl;
- }
- query = QUERY( "_id" << GT << lastId ).sort("_id");
}
}