Index: library/mongodb/nsfmongo.c =================================================================== diff -u -rbcf94f0b3bac771ebd9a65a8eb9dd6030651bb7e -ra5bf2874a6cb0338860062dce1846279c1704444 --- library/mongodb/nsfmongo.c (.../nsfmongo.c) (revision bcf94f0b3bac771ebd9a65a8eb9dd6030651bb7e) +++ library/mongodb/nsfmongo.c (.../nsfmongo.c) (revision a5bf2874a6cb0338860062dce1846279c1704444) @@ -172,7 +172,7 @@ if ( t == 0 ) break; key = bson_iterator_key( &i ); - /*fprintf(stderr, "key %s t %d string %d\n", key, t, bson_string);*/ + /*fprintf(stderr, "BsonToList: key %s t %d string %d\n", key, t, bson_string);*/ switch ( t ){ case bson_int: tag = "integer"; elemObj = Tcl_NewIntObj(bson_iterator_int( &i )); break; @@ -206,7 +206,7 @@ default: tag = "unknown"; elemObj = Tcl_NewStringObj("", 0); - fprintf( stderr , "unknown type : %d\n" , t ); + fprintf( stderr , "BsonToList: unknown type %d\n" , t ); } Tcl_ListObjAppendElement(interp, resultObj, Tcl_NewStringObj(key, -1)); @@ -257,7 +257,7 @@ case 't': /* timestamp */ return bson_timestamp; } - NsfLog(interp, NSF_LOG_WARN, "Treat unknown tag '%s' as string", tag); + NsfLog(interp, NSF_LOG_WARN, "BsonTagToType: Treat unknown tag '%s' as string", tag); return bson_string; } @@ -281,7 +281,7 @@ int result = TCL_OK; bson_type t = BsonTagToType(interp, tag); - /*fprintf(stderr, "add name %s tag %s value '%s'\n", name, tag, ObjStr(value));*/ + /*fprintf(stderr, "BsonAppend: add name %s tag %s value '%s'\n", name, tag, ObjStr(value));*/ switch ( t ){ case bson_string: @@ -359,16 +359,16 @@ int i, objc; Tcl_Obj **objv; - bson_buffer *(*bsonStartFn)( bson_buffer *b, const char *name); - bsonStartFn = (t == bson_object) ? bson_append_start_object : bson_append_start_array; - result = Tcl_ListObjGetElements(interp, value, &objc, &objv); if (result != TCL_OK || objc % 3 != 0) { return NsfPrintError(interp, "invalid %s value contain multiple of 3 elements %s", tag, ObjStr(value)); } - (*bsonStartFn)( bbPtr, name); - + if (t == bson_object) { + bson_append_start_object(bbPtr, name); + } else { + bson_append_start_array(bbPtr, name); + } for (i = 0; i< objc; i += 3) { /*fprintf(stderr, "value %s, i %d, [0]: %s, [1]: %s, [2]: %s\n", ObjStr(value), i, ObjStr(objv[i]), ObjStr(objv[i+1]), ObjStr(objv[i+2]));*/ @@ -466,7 +466,6 @@ buffer[offset] = '\0'; host = buffer; port = atoi(buffer+offset+1); - fprintf(stderr, "port=%d\n", port); } else { /* * The passed string contained no colon. @@ -748,8 +747,8 @@ {-argName "namespace" -required 1} {-argName "query" -required 1 -type tclobj} {-argName "-atts" -required 0 -nrargs 1 -type tclobj} - {-argName "-limit" -required 0 -type int} - {-argName "-skip" -required 0 -type int} + {-argName "-limit" -required 0 -type int32} + {-argName "-skip" -required 0 -type int32} } */ static int @@ -763,6 +762,9 @@ bson query[1]; bson atts[1]; + /*fprintf(stderr, "NsfMongoQuery: namespace %s withLimit %d withSkip %d\n", + namespace, withLimit, withSkip);*/ + if (connPtr == NULL) { return NsfObjErrType(interp, "", connObj, "connection", NULL); } @@ -780,6 +782,7 @@ objc2 = 0; } + /* fprintf(stderr, "query # %d, atts # %d\n", objc1, objc2); */ BsonAppendObjv(interp, query, objc1, objv1); BsonAppendObjv(interp, atts, objc2, objv2); @@ -790,7 +793,7 @@ * http://www.mongodb.org/display/DOCS/Mongo+Wire+Protocol#MongoWireProtocol-OPQUERY */ cursor = mongo_find( connPtr, namespace, query, atts, withLimit, withSkip, 0 ); - while( mongo_cursor_next( cursor ) ) { + while( mongo_cursor_next( cursor ) == MONGO_OK ) { Tcl_ListObjAppendElement(interp, resultObj, BsonToList(interp, (&cursor->current)->data, 0)); }