# File lib/moped/query.rb, line 298
    def modify(change, options = {})
      command = {
        findAndModify: collection.name,
        query: selector
      }.merge(options)

      command[:sort] = operation.selector["$orderby"] if operation.selector["$orderby"]
      command[:fields] = operation.fields if operation.fields
      command[:update] = change unless options[:remove]

      result = session.with(read: :primary) do |sess|
        sess.command(command)["value"]
      end

      # Keeping moped compatibility with mongodb >= 2.2.0-rc0
      options[:upsert] && !result ? {} : result
    end