add a :safe option to Collection's remove()

This commit is contained in:
Patrick Collison 2010-01-16 19:20:33 -03:00 committed by Kyle Banker
parent 41c680b491
commit 8a8d6716b3
1 changed files with 12 additions and 3 deletions

View File

@ -240,15 +240,24 @@ module Mongo
#
# @example remove only documents that have expired:
# users.remove({:expire => {"$lte" => Time.now}})
def remove(selector={})
def remove(selector={}, options={})
# Initial byte is 0.
message = ByteBuffer.new([0, 0, 0, 0])
BSON_RUBY.serialize_cstr(message, "#{@db.name}.#{@name}")
message.put_int(0)
message.put_array(BSON.serialize(selector, false).to_a)
if options[:safe]
@connection.send_message_with_safe_check(Mongo::Constants::OP_DELETE, message,
"db.#{@db.name}.remove(#{selector.inspect})")
# the return value of send_message_with_safe_check isn't actually meaningful --
# only the fact that it didn't raise an error is -- so just return true
true
else
@connection.send_message(Mongo::Constants::OP_DELETE, message,
"db.#{@db.name}.remove(#{selector.inspect})")
end
end
# Update a single document in this collection.
#