def update(selector, document, opts={})
write_concern = get_write_concern(opts, self)
message = BSON::ByteBuffer.new("\0\0\0\0", @connection.max_message_size)
BSON::BSON_RUBY.serialize_cstr(message, "#{@db.name}.#{@name}")
update_options = 0
update_options += 1 if opts[:upsert]
update_options += 2 if opts[:multi]
check_keys = document.keys.first.to_s.start_with?("$") ? false : true
message.put_int(update_options)
message.put_binary(BSON::BSON_CODER.serialize(selector, false, true, @connection.max_bson_size).to_s)
message.put_binary(BSON::BSON_CODER.serialize(document, check_keys, true, @connection.max_bson_size).to_s)
instrument(:update, :database => @db.name, :collection => @name, :selector => selector, :document => document) do
if Mongo::WriteConcern.gle?(write_concern)
@connection.send_message_with_gle(Mongo::Constants::OP_UPDATE, message, @db.name, nil, write_concern)
else
@connection.send_message(Mongo::Constants::OP_UPDATE, message)
end
end
end