Skip to content

Do not raise an error if a non-existent collection is dropped #600

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 10, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/mongo/collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ def create
# Drop the collection. Will also drop all indexes associated with the
# collection.
#
# @note An error returned if the collection doesn't exist is suppressed.
#
# @example Drop the collection.
# collection.drop
#
Expand All @@ -92,6 +94,9 @@ def create
# @since 2.0.0
def drop
database.command(:drop => name)
rescue Error::OperationFailure => ex
raise ex unless ex.message =~ /ns not found/
false
end

# Find documents in the collection.
Expand Down
7 changes: 7 additions & 0 deletions spec/mongo/collection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,13 @@
it 'drops the collection from the database' do
expect(database.collection_names).to_not include('specs')
end

context 'when the collection does not exist' do

it 'does not raise an error' do
expect(database['non-existent-coll'].drop).to be(false)
end
end
end

describe '#find' do
Expand Down