diff --git a/README.md b/README.md index b5e3f4a..fc1f6a6 100755 --- a/README.md +++ b/README.md @@ -267,7 +267,9 @@ Initialize or reinitialize a cursor. * $cursor next -Move the cursor to the next row. +Move the cursor to the next row. Returns true if there is a next row, false if the cursor is exhausted. + +Any error condition (CURSOR_INVALID, CURSOR_PENDING, CURSOR_QUERY_FAIL, CURSOR_BSON_ERROR), it generates a Tcl error and sets the error code to a list consisting of MONGO and the aforementioned condition code. * $cursor to_list diff --git a/generic/cursor.c b/generic/cursor.c index f3c282f..35c7782 100644 --- a/generic/cursor.c +++ b/generic/cursor.c @@ -345,8 +345,14 @@ mongotcl_cursorObjectObjCmd(ClientData cData, Tcl_Interp *interp, int objc, Tcl_ } case OPT_CURSOR_NEXT: { - if (mongo_cursor_next (mc->cursor) != MONGO_OK) { - return mongotcl_setCursorError (interp, mc->cursor); + if (mongo_cursor_next (mc->cursor) == MONGO_OK) { + Tcl_SetObjResult (interp, Tcl_NewBooleanObj (1)); + } else { + if (mc->cursor->err == MONGO_CURSOR_EXHAUSTED) { + Tcl_SetObjResult (interp, Tcl_NewBooleanObj (0)); + } else { + return mongotcl_setCursorError (interp, mc->cursor); + } } break; }