Merge pull request #44 from pto/master
Allow drop_dups on ensure_index as well as on create_index
This commit is contained in:
commit
408fbc1b72
|
@ -163,8 +163,6 @@ module Mongo
|
|||
# This is to prevent any inadvertant failure to close the cursor, as the cursor is explicitly
|
||||
# closed when block code finishes.
|
||||
# @option opts [Integer] :max_scan (nil) Limit the number of items to scan on both collection scans and indexed queries..
|
||||
# @option opts [Boolean] :show_disk_loc (false) Return the disk location of each query result (for debugging).
|
||||
# @option opts [Boolean] :return_key (false) Return the index key used to obtain the result (for debugging).
|
||||
# @option opts [Block] :transformer (nil) a block for tranforming returned documents.
|
||||
# This is normally used by object mappers to convert each returned document to an instance of a class.
|
||||
#
|
||||
|
@ -470,6 +468,7 @@ module Mongo
|
|||
# @return [String] the name of the index.
|
||||
def ensure_index(spec, opts={})
|
||||
now = Time.now.utc.to_i
|
||||
opts[:dropDups] = opts[:drop_dups] if opts[:drop_dups]
|
||||
field_spec = parse_index_spec(spec)
|
||||
|
||||
name = opts[:name] || generate_index_name(field_spec)
|
||||
|
|
|
@ -809,6 +809,14 @@ class TestCollection < Test::Unit::TestCase
|
|||
assert_equal 1, @collection.find({:a => 1}).count
|
||||
end
|
||||
|
||||
should "drop duplicates with ensure_index and drop_dups key" do
|
||||
@collection.insert({:a => 1})
|
||||
@collection.insert({:a => 1})
|
||||
assert_equal 2, @collection.find({:a => 1}).count
|
||||
@collection.ensure_index([['a', Mongo::ASCENDING]], :unique => true, :drop_dups => true)
|
||||
assert_equal 1, @collection.find({:a => 1}).count
|
||||
end
|
||||
|
||||
should "create an index in the background" do
|
||||
if @@version > '1.3.1'
|
||||
@collection.create_index([['b', Mongo::ASCENDING]], :background => true)
|
||||
|
|
Loading…
Reference in New Issue