Skip to content

Commit

Permalink
Add a new run_command method to the mongo object to run a command on …
Browse files Browse the repository at this point in the history
…a MongoDB server.
  • Loading branch information
lehenbauer committed Feb 12, 2014
1 parent ec8f948 commit 3839a67
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions generic/mongotcl.c
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,7 @@ mongotcl_mongoObjectObjCmd(ClientData cData, Tcl_Interp *interp, int objc, Tcl_O
"disconnect",
"check_connection",
"write_concern",
"run_command",
"replica_set_init",
"replica_set_add_seed",
"replica_set_client",
Expand Down Expand Up @@ -614,6 +615,7 @@ mongotcl_mongoObjectObjCmd(ClientData cData, Tcl_Interp *interp, int objc, Tcl_O
OPT_DISCONNECT,
OPT_CHECK_CONNECTION,
OPT_WRITE_CONCERN,
OPT_RUN_COMMAND,
OPT_REPLICA_SET_INIT,
OPT_REPLICA_SET_ADD_SEED,
OPT_REPLICA_SET_CLIENT,
Expand Down Expand Up @@ -801,6 +803,33 @@ mongotcl_mongoObjectObjCmd(ClientData cData, Tcl_Interp *interp, int objc, Tcl_O
break;
}

case OPT_RUN_COMMAND: {
char *database;
bson *commandBson;
bson *outBson;

if (objc != 5) {
Tcl_WrongNumArgs (interp, 2, objv, "db commandBson outBson");
return TCL_ERROR;
}

database = Tcl_GetString(objv[2]);

if (mongotcl_cmdNameObjToBson (interp, objv[3], &commandBson) == TCL_ERROR) {
return TCL_ERROR;
}

if (mongotcl_cmdNameObjToBson (interp, objv[4], &outBson) == TCL_ERROR) {
return TCL_ERROR;
}

if (mongo_run_command (md->conn, database, commandBson, outBson) != MONGO_OK) {
return mongotcl_setMongoError (interp, md->conn);
}

break;
}


case OPT_INSERT_BATCH: {
bson **bsonList;
Expand Down

0 comments on commit 3839a67

Please sign in to comment.