From 0fca829297bf258d96229928a1e3f05eddef9efe Mon Sep 17 00:00:00 2001 From: Karl Lehenbauer Date: Thu, 20 Feb 2014 00:49:43 +0000 Subject: [PATCH] Add "delete" methods for bson, cursor and mongo objects. Doc updates as pointed out by Andreas Kupries. BUGZID: --- README.md | 31 ++++++++++++++++++++++++++++--- generic/bson.c | 10 +++++++++- generic/cursor.c | 9 ++++++++- generic/mongotcl.c | 7 +++++++ 4 files changed, 52 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 078c30c..cb9f53b 100755 --- a/README.md +++ b/README.md @@ -3,9 +3,14 @@ MongoTcl, a Tcl C extension providing a Tcl interface to the MongoDB database MongoTcl provides a Tcl interface to the MongoDB C API. -FA Note +License --- -If pursued far enough, when this is solid enough it will be open sourced. + +Open source under the permissive Berkeley copyright, see file LICENSE + +Requirements +--- +Requires the MongoDB C driver to be installed. Currently builds against version 0.8.1. Building --- @@ -45,7 +50,7 @@ More about bson at http://bsonspec.org/ MongoDB use of BSON at http://docs.mongodb.org/meta-driver/latest/legacy/bson/ -MongoTcl has a bson object and the bson creator is invoked to create bson objects, siilarly to iTcl objects +MongoTcl has a bson object and the bson creator is invoked to create bson objects, simiarly to iTcl objects ```tcl ::mongo::bson create @@ -173,6 +178,10 @@ Enumerate bson object as an array of key-value pairs. Embedded bson arrays and if typeArrayName is specified, for each key of the key-value pairs, an element is inserted into typeArray for the same key with the value being the name of the bson datatype such as int, double, string, oid, etc. +* $bson delete + +Delete the bson object. + * $bson print Print is for debugging only, it sort of shows you what's in the bson object. @@ -289,6 +298,14 @@ Drop a collection. Drop a database. +* $mongo delete + +Delete the mongo object. Can also be done by doing a + +```tcl + rename $mongo "" +``` + Cursor Methods --- @@ -354,6 +371,9 @@ Allow reads even if a shard is down. Set what fields are returned. fieldList is a list of field names with 1 or 0. 1 says to include the field, 0 says to exclude it. The fieldList is sticky for future queries. This may change. See http://docs.mongodb.org/manual/tutorial/project-fields-from-query-results/ for how the 1/0 thing works. +* $cursor delete + +Delete the cursor object. Search --- @@ -394,6 +414,11 @@ Example When you're done using the bson object, destroy it by doing a +```tcl + $bson delete +``` +or, if you prefer... + ```tcl rename $bson "" ``` diff --git a/generic/bson.c b/generic/bson.c index 56f18f4..faf254c 100644 --- a/generic/bson.c +++ b/generic/bson.c @@ -833,6 +833,7 @@ mongotcl_bsonObjectObjCmd(ClientData cData, Tcl_Interp *interp, int objc, Tcl_Ob "to_array", "array_set", "finish", + "delete", "print", NULL }; @@ -858,6 +859,7 @@ mongotcl_bsonObjectObjCmd(ClientData cData, Tcl_Interp *interp, int objc, Tcl_Ob OPT_TO_ARRAY, OPT_ARRAY_SET, OPT_FINISH, + OPT_DELETE, OPT_PRINT }; @@ -1238,7 +1240,13 @@ mongotcl_bsonObjectObjCmd(ClientData cData, Tcl_Interp *interp, int objc, Tcl_Ob return mongotcl_setBsonError (interp, bd->bson); } break; - } + } + + case OPT_DELETE: { + Tcl_DeleteCommandFromToken (interp, bd->cmdToken); + break; + } + case OPT_PRINT: { bson_print (bd->bson); diff --git a/generic/cursor.c b/generic/cursor.c index 0ced263..1a09e3a 100644 --- a/generic/cursor.c +++ b/generic/cursor.c @@ -218,6 +218,7 @@ mongotcl_cursorObjectObjCmd(ClientData cData, Tcl_Interp *interp, int objc, Tcl_ "set_limit", "set_options", "data", + "delete", NULL }; @@ -231,7 +232,8 @@ mongotcl_cursorObjectObjCmd(ClientData cData, Tcl_Interp *interp, int objc, Tcl_ OPT_CURSOR_SET_SKIP, OPT_CURSOR_SET_LIMIT, OPT_CURSOR_SET_OPTIONS, - OPT_CURSOR_DATA + OPT_CURSOR_DATA, + OPT_CURSOR_DELETE }; /* basic validation of command line arguments */ @@ -442,6 +444,11 @@ mongotcl_cursorObjectObjCmd(ClientData cData, Tcl_Interp *interp, int objc, Tcl_ } break; } + + case OPT_CURSOR_DELETE: { + Tcl_DeleteCommandFromToken (interp, mc->cmdToken); + break; + } } return TCL_OK; diff --git a/generic/mongotcl.c b/generic/mongotcl.c index 151dfe6..fbbd967 100644 --- a/generic/mongotcl.c +++ b/generic/mongotcl.c @@ -201,6 +201,7 @@ mongotcl_mongoObjectObjCmd(ClientData cData, Tcl_Interp *interp, int objc, Tcl_O "add_user", "drop_collection", "drop_db", + "delete", NULL }; @@ -233,6 +234,7 @@ mongotcl_mongoObjectObjCmd(ClientData cData, Tcl_Interp *interp, int objc, Tcl_O OPT_CMD_ADD_USER, OPT_CMD_DROP_COLLECTION, OPT_CMD_DROP_DB, + OPT_DELETE }; /* basic validation of command line arguments */ @@ -965,6 +967,11 @@ mongotcl_mongoObjectObjCmd(ClientData cData, Tcl_Interp *interp, int objc, Tcl_O } break; } + + case OPT_DELETE: { + Tcl_DeleteCommandFromToken (interp, md->cmdToken); + break; + } } return TCL_OK; }