Skip to content

Commit

Permalink
Get rid of the bson method of the cursor object. Replace it with to_l…
Browse files Browse the repository at this point in the history
…ist. 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:
  • Loading branch information
lehenbauer committed Feb 13, 2014
1 parent dbf785d commit 4ae77dd
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 13 deletions.
25 changes: 21 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
---
Expand Down
19 changes: 10 additions & 9 deletions generic/cursor.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,28 +135,28 @@ 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",
"set_skip",
"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 */
Expand Down Expand Up @@ -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: {
Expand Down
4 changes: 4 additions & 0 deletions generic/mongotcl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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[]);

Expand Down

0 comments on commit 4ae77dd

Please sign in to comment.