Merge branch 'master' of git://github.com/jimm/mongo-ruby-driver
This commit is contained in:
commit
8bcabd977d
3
README
3
README
@ -54,9 +54,6 @@ type
|
||||
|
||||
* Implement Babble's algorithm for ObjectID. Implement Comparable.
|
||||
|
||||
* Change find(selector={}, fields=nil, options={}) to find(selector={},
|
||||
options={})
|
||||
|
||||
* ObjectID equality.
|
||||
|
||||
* Capped collection support.
|
||||
|
@ -26,9 +26,16 @@ module XGen
|
||||
@name = name
|
||||
end
|
||||
|
||||
# Options:
|
||||
# * <tt>:fields</tt> - Array of collection field names; only those will be returned (plus _id if defined)
|
||||
# * <tt>:offset</tt> - Start at this record when returning records
|
||||
# * <tt>:limit</tt> - Maximum number of records to return
|
||||
# * <tt>:sort</tt> - Hash of field names as keys and 1/-1 as values; 1 == ascending, -1 == descending
|
||||
# <tt>
|
||||
def find(selector={}, options={})
|
||||
options = { :fields => nil, :offset => 0, :limit => 0, :sort => nil}.update(options)
|
||||
@db.query(@name, Query.new(selector, options[:fields], options[:offset], options[:limit], options[:sort]))
|
||||
fields = options.delete(:fields)
|
||||
fields = nil if fields && fields.empty?
|
||||
@db.query(@name, Query.new(selector, fields, options[:offset] || 0, options[:limit] || 0, options[:sort]))
|
||||
end
|
||||
|
||||
def insert(*objects)
|
||||
|
@ -181,7 +181,7 @@ class DBAPITest < Test::Unit::TestCase
|
||||
|
||||
def test_array
|
||||
@coll << {'b' => [1, 2, 3]}
|
||||
rows = @coll.find({}, {'b' => 1}).collect
|
||||
rows = @coll.find({}, {:fields => ['b']}).collect
|
||||
assert_equal 1, rows.length
|
||||
assert_equal [1, 2, 3], rows[0]['b']
|
||||
end
|
||||
@ -189,7 +189,7 @@ class DBAPITest < Test::Unit::TestCase
|
||||
def test_regex
|
||||
regex = /foobar/i
|
||||
@coll << {'b' => regex}
|
||||
rows = @coll.find({}, {'b' => 1}).collect
|
||||
rows = @coll.find({}, {:fields => ['b']}).collect
|
||||
assert_equal 1, rows.length
|
||||
assert_equal regex, rows[0]['b']
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user