From 4ae77dd9c4208315f2df6405f98e799615dbbc29 Mon Sep 17 00:00:00 2001 From: Karl Lehenbauer Date: Thu, 13 Feb 2014 19:03:25 +0000 Subject: [PATCH] Get rid of the bson method of the cursor object. Replace it with to_list. We'll add similar bson-walking capabilities once they exist in the bson object. This was necessitated by that cursor's bson data belongs to them while we allocate the bson structures in bson objects and it was hard to disambiguate. Update docs. BUGZID: --- README.md | 25 +++++++++++++++++++++---- generic/cursor.c | 19 ++++++++++--------- generic/mongotcl.h | 4 ++++ 3 files changed, 35 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 004f5c3..38756a5 100755 --- a/README.md +++ b/README.md @@ -180,9 +180,9 @@ There's a compile warning on this. It's probably coredump. Removes a document from a MongoDB server. bson is the bson query. -* $mongo cursor $name +* $mongo cursor name -Create a cursor for this MongoDB connection. +Create a cursor for this MongoDB connection. Name is the name of the object created. If name is #auto, a unique name will be automatically generated and returned. * $mongo find $namespace $bsonQuery $bsonFields $limit $skip $options @@ -228,6 +228,10 @@ Disconnect from the database. Check the database connection status. Returns 0 or 1. +* $mongo is_master ?bson? + +Return 1 if we are connected to the master, 0 otherwise. bson, if present, is the name of a bson object that will receive detailed information about the database. + * $mongo replica_set_init * $mongo replica_set_add_seed $address $port @@ -257,9 +261,17 @@ Drop a database. Cursor Methods --- -* $cursor init +* $cursor init $namespace + +Initialize or reinitialize a cursor. + +* $cursor next + +Move the cursor to the next row. -Initialize or reinitialize a cursor. Cursors are automatically initialized upon creation. +* $cursor to_list + +Return the bson object of the current row as a list. * $cursor set_query $bson @@ -301,6 +313,11 @@ Streem in multiple 'more' packages... (?) Allow reads even if a shard is down. +* $cursor set_fields bson + +Set what fields are returned. bson is a bson object containing the fields. Expect this to change to take a list of fields and make the bson object behind your back. + + Example --- diff --git a/generic/cursor.c b/generic/cursor.c index 8502102..79ce552 100644 --- a/generic/cursor.c +++ b/generic/cursor.c @@ -135,6 +135,8 @@ mongotcl_cursorObjectObjCmd(ClientData cData, Tcl_Interp *interp, int objc, Tcl_ mongotcl_cursorClientData *mc = (mongotcl_cursorClientData *)cData; static CONST char *options[] = { + "next", + "to_list", "init", "set_query", "set_fields", @@ -142,21 +144,19 @@ mongotcl_cursorObjectObjCmd(ClientData cData, Tcl_Interp *interp, int objc, Tcl_ "set_limit", "set_options", "data", - "bson", - "next", NULL }; enum options { + OPT_CURSOR_NEXT, + OPT_CURSOR_TO_LIST, OPT_CURSOR_INIT, OPT_CURSOR_SET_QUERY, OPT_CURSOR_SET_FIELDS, OPT_CURSOR_SET_SKIP, OPT_CURSOR_SET_LIMIT, OPT_CURSOR_SET_OPTIONS, - OPT_CURSOR_DATA, - OPT_CURSOR_BSON, - OPT_CURSOR_NEXT + OPT_CURSOR_DATA }; /* basic validation of command line arguments */ @@ -333,13 +333,14 @@ mongotcl_cursorObjectObjCmd(ClientData cData, Tcl_Interp *interp, int objc, Tcl_ break; } - case OPT_CURSOR_BSON: { - if (objc != 3) { - Tcl_WrongNumArgs (interp, 2, objv, "bsonName"); + case OPT_CURSOR_TO_LIST: { + if (objc != 2) { + Tcl_WrongNumArgs (interp, 1, objv, "to_list"); return TCL_ERROR; } - return mongotcl_cmdNameObjSetBson (interp, objv[2], mongo_cursor_bson (mc->cursor)); + Tcl_SetObjResult (interp, mongotcl_bsontolist (interp, mongo_cursor_bson (mc->cursor))); + break; } case OPT_CURSOR_NEXT: { diff --git a/generic/mongotcl.h b/generic/mongotcl.h index f14bea3..418ec0c 100644 --- a/generic/mongotcl.h +++ b/generic/mongotcl.h @@ -28,6 +28,10 @@ mongotcl_cmdNameObjToBson (Tcl_Interp *interp, Tcl_Obj *commandNameObj, bson **b extern int mongotcl_cmdNameObjSetBson (Tcl_Interp *interp, Tcl_Obj *commandNameObj, bson *newBson); +extern Tcl_Obj * +mongotcl_bsontolist(Tcl_Interp *interp, const bson *b); + + extern int mongotcl_mongoObjCmd(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objvp[]);