summaryrefslogtreecommitdiff
path: root/client/examples/tutorial.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'client/examples/tutorial.cpp')
-rw-r--r--client/examples/tutorial.cpp64
1 files changed, 32 insertions, 32 deletions
diff --git a/client/examples/tutorial.cpp b/client/examples/tutorial.cpp
index 28e1b27..3cdf359 100644
--- a/client/examples/tutorial.cpp
+++ b/client/examples/tutorial.cpp
@@ -23,45 +23,45 @@
using namespace mongo;
void printIfAge(DBClientConnection& c, int age) {
- auto_ptr<DBClientCursor> cursor = c.query("tutorial.persons", QUERY( "age" << age ).sort("name") );
- while( cursor->more() ) {
- BSONObj p = cursor->next();
- cout << p.getStringField("name") << endl;
- }
+ auto_ptr<DBClientCursor> cursor = c.query("tutorial.persons", QUERY( "age" << age ).sort("name") );
+ while( cursor->more() ) {
+ BSONObj p = cursor->next();
+ cout << p.getStringField("name") << endl;
+ }
}
void run() {
- DBClientConnection c;
- c.connect("localhost"); //"192.168.58.1");
- cout << "connected ok" << endl;
- BSONObj p = BSON( "name" << "Joe" << "age" << 33 );
- c.insert("tutorial.persons", p);
- p = BSON( "name" << "Jane" << "age" << 40 );
- c.insert("tutorial.persons", p);
- p = BSON( "name" << "Abe" << "age" << 33 );
- c.insert("tutorial.persons", p);
- p = BSON( "name" << "Samantha" << "age" << 21 << "city" << "Los Angeles" << "state" << "CA" );
- c.insert("tutorial.persons", p);
+ DBClientConnection c;
+ c.connect("localhost"); //"192.168.58.1");
+ cout << "connected ok" << endl;
+ BSONObj p = BSON( "name" << "Joe" << "age" << 33 );
+ c.insert("tutorial.persons", p);
+ p = BSON( "name" << "Jane" << "age" << 40 );
+ c.insert("tutorial.persons", p);
+ p = BSON( "name" << "Abe" << "age" << 33 );
+ c.insert("tutorial.persons", p);
+ p = BSON( "name" << "Samantha" << "age" << 21 << "city" << "Los Angeles" << "state" << "CA" );
+ c.insert("tutorial.persons", p);
- c.ensureIndex("tutorial.persons", fromjson("{age:1}"));
+ c.ensureIndex("tutorial.persons", fromjson("{age:1}"));
- cout << "count:" << c.count("tutorial.persons") << endl;
+ cout << "count:" << c.count("tutorial.persons") << endl;
- auto_ptr<DBClientCursor> cursor = c.query("tutorial.persons", BSONObj());
- while( cursor->more() ) {
- cout << cursor->next().toString() << endl;
- }
+ auto_ptr<DBClientCursor> cursor = c.query("tutorial.persons", BSONObj());
+ while( cursor->more() ) {
+ cout << cursor->next().toString() << endl;
+ }
- cout << "\nprintifage:\n";
- printIfAge(c, 33);
+ cout << "\nprintifage:\n";
+ printIfAge(c, 33);
}
-int main() {
- try {
- run();
- }
- catch( DBException &e ) {
- cout << "caught " << e.what() << endl;
- }
- return 0;
+int main() {
+ try {
+ run();
+ }
+ catch( DBException &e ) {
+ cout << "caught " << e.what() << endl;
+ }
+ return 0;
}