Index: library/mongodb/nx-mongo.tcl =================================================================== diff -u -rdd3cfbfdee40f0a2fa5a60bdb07c2e8d9c863dc4 -r9cdb38c7c44b7c94af338e90c089aa2e0cd77201 --- library/mongodb/nx-mongo.tcl (.../nx-mongo.tcl) (revision dd3cfbfdee40f0a2fa5a60bdb07c2e8d9c863dc4) +++ library/mongodb/nx-mongo.tcl (.../nx-mongo.tcl) (revision 9cdb38c7c44b7c94af338e90c089aa2e0cd77201) @@ -710,6 +710,7 @@ {-orderby ""} {-limit:integer} {-skip:integer} + {-asJSON:boolean 0} } { set result [list] set opts [list] @@ -719,10 +720,31 @@ [:bson cond $cond] \ -opts [:bson opts -orderby $orderby -atts $atts {*}$opts] ] - foreach tuple $fetched { - lappend result [:bson create $tuple] + if {$asJSON} { + # + # Return fetched tuples form mongoDB in form of a JSON array + # (between square brackets). + # + # The last 5 lines of this proc could be written as the following line, + # but we keep it traditional... + # + # return [subst { \[ [join [lmap tuple $fetched {mongo::json::generate $tuple}] ,\n] \] }] + # + set tuples [list] + foreach tuple $fetched { + lappend tuples [mongo::json::generate $tuple] + } + return [subst { \[ [join $tuples ",\n"] \] }] + + } else { + # + # Create from the fetched tuples form mongoDB objects. + # + foreach tuple $fetched { + lappend result [:bson create $tuple] + } + return $result } - return $result } :public method show {