summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore3
-rw-r--r--README4
-rw-r--r--SConstruct40
-rw-r--r--client/dbclient.h1
-rw-r--r--client/examples/first.cpp63
5 files changed, 111 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
index d66b5088620..716ed63065d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -25,3 +25,6 @@ logs
# binaryies
mongodump
mongoimport
+firstExample
+libmongoclient.*
+test
diff --git a/README b/README
index ef38588ba2e..d05ad458c2b 100644
--- a/README
+++ b/README
@@ -36,6 +36,8 @@ Mongo uses memory mapped files. If built as a 32 bit executable, you will
not be able to work with large (multi-gigabyte) databases. However, 32 bit
builds should work fine with small development databases.
+To compile the unit tests, you need to install the unit test framework from:
+ http://unittest.red-bean.com/
--- WINDOWS ---
@@ -55,3 +57,5 @@ COMPILING
mkdir \data\
mkdir \data\db
db\db run
+
+
diff --git a/SConstruct b/SConstruct
index 88030148146..f2242e2bd93 100644
--- a/SConstruct
+++ b/SConstruct
@@ -102,6 +102,18 @@ if nix:
for b in boostLibs:
env.Append( LIBS=[ "boost_" + b ] )
+clientEnv = env.Clone();
+clientEnv.Append( CPPPATH=["../"] )
+clientEnv.Append( LIBS=["unittest" , "libmongoclient.a"] )
+clientEnv.Append( LIBPATH=["."] )
+
+# SYSTEM CHECKS
+configure = env.Configure()
+
+
+
+# ----- TARGETS ------
+
# main db target
Default( env.Program( "db/db" , commonFiles + coreDbFiles + [ "db/db.cpp" ] ) )
@@ -115,3 +127,31 @@ env.Program( "db/dbgrid" , commonFiles + Glob( "dbgrid/*.cpp" ) )
# c++ library
env.Library( "mongoclient" , commonFiles + coreDbFiles )
+
+# examples
+clientEnv.Program( "firstExample" , [ "client/examples/first.cpp" ] )
+
+# testing
+clientEnv.Program( "test" , Glob( "dbtests/*.cpp" ) )
+
+
+# ---- INSTALL -------
+
+installDir = "/opt/mongo"
+
+#binaries
+env.Install( installDir + "/bin" , "mongodump" )
+env.Install( installDir + "/bin" , "mongoimport" )
+env.Install( installDir + "/bin" , "db/db" )
+
+#headers
+for id in [ "" , "client/" , "util/" , "grid/" , "db/" ]:
+ env.Install( installDir + "/include/mongo/" + id , Glob( id + "*.h" ) )
+
+#lib
+env.Install( installDir + "/lib" , "libmongoclient.a" )
+env.Install( installDir + "/lib/mongo-jars" , Glob( "jars/*" ) )
+
+#final alias
+env.Alias( "install" , installDir )
+
diff --git a/client/dbclient.h b/client/dbclient.h
index 58fe12f4575..c412ed0cca8 100644
--- a/client/dbclient.h
+++ b/client/dbclient.h
@@ -18,6 +18,7 @@
#pragma once
+#include "../stdafx.h"
#include "../grid/message.h"
#include "../db/jsobj.h"
diff --git a/client/examples/first.cpp b/client/examples/first.cpp
new file mode 100644
index 00000000000..2fef4fa0710
--- /dev/null
+++ b/client/examples/first.cpp
@@ -0,0 +1,63 @@
+// first.cpp
+
+/**
+ * this is a good first example of how to use mongo from c++
+ */
+
+#include <iostream>
+
+#include "mongo/client/dbclient.h"
+
+using namespace std;
+
+void insert( DBClientConnection & conn , const char * name , int num ){
+ BSONObjBuilder obj;
+ obj.append( "name" , name );
+ obj.append( "num" , num );
+ conn.insert( "test.people" , obj.doneAndDecouple() );
+}
+
+int main(){
+
+ DBClientConnection conn;
+ string errmsg;
+ if ( ! conn.connect( "127.0.0.1" , errmsg ) ){
+ cout << "couldn't connect : " << errmsg << endl;
+ throw -11;
+ }
+
+ { // clean up old data from any previous tests
+ BSONObjBuilder query;
+ conn.remove( "test.people" , query.doneAndDecouple() );
+ }
+
+ insert( conn , "eliot" , 15 );
+ insert( conn , "sara" , 23 );
+
+ {
+ BSONObjBuilder query;
+ auto_ptr<DBClientCursor> cursor = conn.query( "test.people" , query.doneAndDecouple() );
+ cout << "using cursor" << endl;
+ while ( cursor->more() ){
+ BSONObj obj = cursor->next();
+ cout << "\t" << obj.jsonString() << endl;
+ }
+
+ }
+
+ {
+ BSONObjBuilder query;
+ query.append( "name" , "eliot" );
+ BSONObj res = conn.findOne( "test.people" , query.doneAndDecouple() );
+ cout << res.isEmpty() << "\t" << res.jsonString() << endl;
+ }
+
+ {
+ BSONObjBuilder query;
+ query.append( "name" , "asd" );
+ BSONObj res = conn.findOne( "test.people" , query.doneAndDecouple() );
+ cout << res.isEmpty() << "\t" << res.jsonString() << endl;
+ }
+
+
+}