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
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
Execute a $findAndModify on the query.

 @example Find and modify a document, returning the original.
   db[:bands].find.modify({ "$inc" => { likes: 1 }})

 @example Find and modify a document, returning the updated document.
   db[:bands].find.modify({ "$inc" => { likes: 1 }}, new: true)

 @example Find and return a document, removing it from the database.
   db[:bands].find.modify({}, remove: true)

 @example Find and return a document, upserting if no match found.
   db[:bands].find.modify({}, upsert: true, new: true)

 @param [ Hash ] change The changes to make to the document.
 @param [ Hash ] options The options.

 @option options :new Set to true if you want to return the updated document.
 @option options :remove Set to true if the document should be deleted.
 @option options :upsert Set to true if you want to upsert

 @return [ Hash ] The document.

 @since 1.0.0