diff --git a/README.rdoc b/README.rdoc index 80b1d72..704aa4c 100644 --- a/README.rdoc +++ b/README.rdoc @@ -332,6 +332,9 @@ Jack Chen, chendo on github Kyle Banker, banker on github * #limit and #skip methods for Cursor instances +Michael Bernstein, mrb on github +* #sort method for Cursor instances + = License Copyright 2008-2009 10gen Inc. diff --git a/lib/mongo/cursor.rb b/lib/mongo/cursor.rb index 9ad3d3f..1c3b908 100644 --- a/lib/mongo/cursor.rb +++ b/lib/mongo/cursor.rb @@ -72,12 +72,17 @@ module Mongo return 0 if response['errmsg'] == "ns missing" raise OperationFailure, "Count failed: #{response['errmsg']}" end - - # Sort the results of the query with a hash of keys and orders + + # Sort this cursor's result # - # Either hash of field names as keys and 1/-1 as values; 1 == - # ascending, -1 == descending, or array of field names (all - # assumed to be sorted in ascending order). + # Takes either a hash of field names as keys and 1/-1 as values; 1 == + # ascending, -1 == descending, or array of field names (all assumed to be + # sorted in ascending order). + # + # Raises InvalidOperation if this cursor has already been used. + # + # This method overrides any sort order specified in the Collection#find + # method, and only the last sort applied has an effect def sort(order) raise InvalidOperation, "can't call Cursor#sort on a used cursor" if @query_run @query.order_by = order @@ -86,7 +91,10 @@ module Mongo # Limits the number of results to be returned by this cursor. # - # Note: this method overrides any limit specified in the #find method. + # Raises InvalidOperation if this cursor has already been used. + # + # This method overrides any limit specified in the Collection#find method, + # and only the last limit applied has an effect. def limit(number_to_return) check_modifiable raise ArgumentError, "limit requires an integer" unless number_to_return.is_a? Integer @@ -97,7 +105,10 @@ module Mongo # Skips the first +number_to_skip+ results of this cursor. # - # Note: this method overrides any offset specified in the #find method. + # Raises InvalidOperation if this cursor has already been used. + # + # This method overrides any offset specified in the Collection#find method, + # and only the last skip applied has an effect. def skip(number_to_skip) check_modifiable raise ArgumentError, "skip requires an integer" unless number_to_skip.is_a? Integer