Index: library/mongodb/README =================================================================== diff -u -N -re934af71d6cf1335ea45fbaae797f87090b9e365 -r64cdee65763cc97c7ae64f6b522c1dee4707ed6e --- library/mongodb/README (.../README) (revision e934af71d6cf1335ea45fbaae797f87090b9e365) +++ library/mongodb/README (.../README) (revision 64cdee65763cc97c7ae64f6b522c1dee4707ed6e) @@ -1,47 +1,52 @@ + Interface between mongoDB and the Next Scripting Framework Ingredients: https://github.com/mongodb/mongo https://github.com/mongodb/mongo-c-driver -The current version is tested with -- MongoDB v2.6.1 -- mongodb-c-driver 0.96 +The current version is tested with +- Tcl 8.5 and Tcl 8.6 +- MongoDB v2.6.5 (released Aug 10, 2014) +- mongodb-c-driver 1.0.2 (released Oct 9, 2014) -Compile or obtain mongodb (the database). +Follow the following steps to get MongoDB up and running +and to compile the MongoDB driver for nx: -Compile or obtain the mongo-c-driver (client interface) +- Compile or obtain mongodb (the database). +- Compile or obtain the mongo-c-driver (client interface) + cd /usr/local/src git clone https://github.com/mongodb/mongo-c-driver cd mongo-c-driver sh autogen.sh make sudo make install -If you experience errors during autogen on debian, you might have to +If you experience errors during autogen on debian, you might have to apt-get install libtool If configure complains about not finding bson, you might have to do export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig -Assume the following installation directories +Assume the following installation directories - Tcl: /usr/local/ns/lib/ - mongo-c-driver: /usr/local/src/mongo-c-driver/ -configure the mongodb nsf interface via the following -command in the directory nsf*/library/mongodb/ +configure the mongodb nsf interface via the following +command in the directory nsf*/library/mongodb/ +You will probably have to adjust the paths. - ./configure --with-tcl=/usr/local/ns/lib/ --with-nsf=../../ \ + ./configure --with-tcl=/usr/local/ns/lib/ --prefix=/usr/local/ns --with-nsf=../../ \ --with-mongoc=/usr/local/src/mongo-c-driver/src/mongoc/,/usr/local/src/mongo-c-driver/.libs \ --with-bson=/usr/local/src/mongo-c-driver/src/libbson/src/bson \ - --enable-threads --enable-symbols --prefix=/usr/local/ns + --enable-threads --enable-symbols - -In order to run the sample script, +In order to run the sample script, * first start the mongdb (eg. mongod) * go to your nsf source directory @@ -51,26 +56,26 @@ export DYLD_LIBRARY_PATH=/usr/local/lib:`pwd` - * run + * run ./nxsh library/mongodb/tests/nsf-mongo.test - + The script is using the low level interface (nsf::mongo) and has a few insert, query and delete statements, some of these are commented out. - * run + * run ./nxsh library/mongodb/example-nx-mongo.tcl - + This example script is using the higher level object oriented interface for nx (nx::mongo). After running this script, you should could check the content in MongoDB: % mongo - MongoDB shell version: 2.6.1 + MongoDB shell version: 2.6.5 connecting to: test > use tutorial switched to db tutorial @@ -81,7 +86,7 @@ { "_id" : ObjectId("530c6e4649686ad16e261f84"), "name" : "Joe", "projects" : "abc", "age" : 23, "classes" : [ DBRef("courses", ObjectId("100000000000000000000000")) ] } { "_id" : ObjectId("530c6e4649686ad16e261f85"), "name" : "Franz", "info" : { "x" : 203, "y" : 102 }, "age" : 29, "projects" : "gtat" } { "_id" : ObjectId("530c6e4649686ad16e261f86"), "name" : "Selim", "ts" : Timestamp(1302945037, 1), "d" : ISODate("2011-04-16T09:53:39.279Z") } - > + > * Further sample-scripts: Index: library/mongodb/mongoAPI.h =================================================================== diff -u -N -raaf54b0b2c0f94de46aefd72cc8172a77359c073 -r64cdee65763cc97c7ae64f6b522c1dee4707ed6e --- library/mongodb/mongoAPI.h (.../mongoAPI.h) (revision aaf54b0b2c0f94de46aefd72cc8172a77359c073) +++ library/mongodb/mongoAPI.h (.../mongoAPI.h) (revision 64cdee65763cc97c7ae64f6b522c1dee4707ed6e) @@ -251,6 +251,7 @@ return NsfCollectionClose(interp, collectionPtr,pc.objv[0]); } else { + return TCL_ERROR; } } @@ -272,6 +273,7 @@ return NsfCollectionOpen(interp, connPtr, dbname, collectionname); } else { + return TCL_ERROR; } } @@ -291,6 +293,7 @@ return NsfMongoClose(interp, connPtr,pc.objv[0]); } else { + return TCL_ERROR; } } @@ -311,6 +314,7 @@ return NsfMongoCollectionCount(interp, collectionPtr, query); } else { + return TCL_ERROR; } } @@ -331,6 +335,7 @@ return NsfMongoCollectionDelete(interp, collectionPtr, condition); } else { + return TCL_ERROR; } } @@ -357,6 +362,7 @@ return NsfMongoCollectionIndex(interp, collectionPtr, attributes, withName, withBackground, withDropdups, withSparse, withTtl, withUnique); } else { + return TCL_ERROR; } } @@ -377,6 +383,7 @@ return NsfMongoCollectionInsert(interp, collectionPtr, values); } else { + return TCL_ERROR; } } @@ -400,6 +407,7 @@ return NsfMongoCollectionQuery(interp, collectionPtr, query, withAtts, withLimit, withSkip); } else { + return TCL_ERROR; } } @@ -420,6 +428,7 @@ return NsfMongoCollectionStats(interp, collectionPtr, withOptions); } else { + return TCL_ERROR; } } @@ -443,6 +452,7 @@ return NsfMongoCollectionUpdate(interp, collectionPtr, cond, values, withUpsert, withAll); } else { + return TCL_ERROR; } } @@ -462,6 +472,7 @@ return NsfMongoConnect(interp, withUri); } else { + return TCL_ERROR; } } @@ -485,6 +496,7 @@ return NsfMongoCursorAggregate(interp, collectionPtr, pipeline, options, withTailable, withAwaitdata); } else { + return TCL_ERROR; } } @@ -504,6 +516,7 @@ return NsfMongoCursorClose(interp, cursorPtr,pc.objv[0]); } else { + return TCL_ERROR; } } @@ -529,6 +542,7 @@ return NsfMongoCursorFind(interp, collectionPtr, query, withAtts, withLimit, withSkip, withTailable, withAwaitdata); } else { + return TCL_ERROR; } } @@ -548,6 +562,7 @@ return NsfMongoCursorNext(interp, cursorPtr); } else { + return TCL_ERROR; } } @@ -567,6 +582,7 @@ return NsfMongoGridFSClose(interp, gfsPtr,pc.objv[0]); } else { + return TCL_ERROR; } } @@ -588,6 +604,7 @@ return NsfMongoGridFSOpen(interp, connPtr, dbname, prefix); } else { + return TCL_ERROR; } } @@ -607,6 +624,7 @@ return NsfMongoGridFileClose(interp, gridfilePtr,pc.objv[0]); } else { + return TCL_ERROR; } } @@ -631,6 +649,7 @@ return NsfMongoGridFileCreate(interp, withSource, gfsPtr, value, name, contenttype, withMetadata); } else { + return TCL_ERROR; } } @@ -651,6 +670,7 @@ return NsfMongoGridFileDelete(interp, gfsPtr, query); } else { + return TCL_ERROR; } } @@ -670,6 +690,7 @@ return NsfMongoGridFileGetContentType(interp, gridfilePtr); } else { + return TCL_ERROR; } } @@ -689,6 +710,7 @@ return NsfMongoGridFileGetContentlength(interp, gridfilePtr); } else { + return TCL_ERROR; } } @@ -708,6 +730,7 @@ return NsfMongoGridFileGetMetaData(interp, gridfilePtr); } else { + return TCL_ERROR; } } @@ -728,6 +751,7 @@ return NsfMongoGridFileOpen(interp, gfsPtr, query); } else { + return TCL_ERROR; } } @@ -748,6 +772,7 @@ return NsfMongoGridFileRead(interp, gridfilePtr, size); } else { + return TCL_ERROR; } } @@ -768,6 +793,7 @@ return NsfMongoGridFileSeek(interp, gridfilePtr, offset); } else { + return TCL_ERROR; } } @@ -790,6 +816,7 @@ return NsfMongoRunCmd(interp, withNocomplain, connPtr, db, cmd); } else { + return TCL_ERROR; } } @@ -809,6 +836,7 @@ return NsfMongoStatus(interp, connPtr,pc.objv[0]); } else { + return TCL_ERROR; } } Index: library/mongodb/tests/nx-mongo.test =================================================================== diff -u -N -rcef3de5c4f65e767d0c66389bacc77bc3c2e5a68 -r64cdee65763cc97c7ae64f6b522c1dee4707ed6e --- library/mongodb/tests/nx-mongo.test (.../nx-mongo.test) (revision cef3de5c4f65e767d0c66389bacc77bc3c2e5a68) +++ library/mongodb/tests/nx-mongo.test (.../nx-mongo.test) (revision 64cdee65763cc97c7ae64f6b522c1dee4707ed6e) @@ -13,29 +13,30 @@ # Establish connection to the database ? {::nx::mongo::db connect -db "tutorial"} mongoc_client_t:0 -# Make sure, we start always from scratch - -nx::mongo::db delete tutorial.persons {} - # # Create or lookup collection handle; the first operation is a create, # the second a lookup. # ? {::nx::mongo::db collection tutorial.persons} "mongoc_collection_t:0" ? {::nx::mongo::db collection tutorial.persons} "mongoc_collection_t:0" -if {[::mongo::collection::count [::nx::mongo::db collection tutorial.persons] {}] > 0} { - # when we create a capped colletion, we have to use "drop collection" to get rid of it. - nx::mongo::db drop collection persons -} +# +# When we create a capped colletion, we cannot use +# +# nx::mongo::db delete tutorial.persons {} +# +# but have to use "drop collection" to get rid of it (this is enforced +# by MongoDB 2.6.3 or newer). +nx::mongo::db drop collection persons + # # Create the application class "Person" # ? { nx::mongo::Class create Person { :index name - + :property name:required :property projects:0..n {set :incremental 1} :property age:integer @@ -49,8 +50,8 @@ ? { nsf::is object [set p [Person new -name Gustaf -projects {nsf nx nxmongo} -age 53]]} 1 ? { nx::mongo::db is_oid [$p save]} 1 ? { $p destroy; nsf::is object $p} 0 - + # # The insert operation of above can be achieved with less typing via # the conveniance method "insert":