class Mongo::Operation::Update::Result

Defines custom behavior of results for an update.

@since 2.0.0

Constants

MODIFIED

The number of modified docs field in the result.

@since 2.0.0

UPSERTED

The upserted docs field in the result.

@since 2.0.0

Public Instance Methods

bulk_result() click to toggle source
# File lib/mongo/operation/update/result.rb, line 90
def bulk_result
  BulkResult.new(@replies)
end
matched_count() click to toggle source

Get the number of documents matched.

@example Get the matched count.

result.matched_count

@return [ Integer ] The matched count.

@since 2.0.0

# File lib/mongo/operation/update/result.rb, line 42
def matched_count
  return 0 unless acknowledged?
  if upsert?
    0
  else
    n
  end
end
modified_count() click to toggle source

Get the number of documents modified.

@example Get the modified count.

result.modified_count

@return [ Integer ] The modified count.

@since 2.0.0

# File lib/mongo/operation/update/result.rb, line 59
def modified_count
  return 0 unless acknowledged?
  first[MODIFIED]
end
upserted_count() click to toggle source

Returns the number of documents upserted.

@example Get the number of upserted documents.

result.upserted_count

@return [ Integer ] The number upserted.

@since 2.4.2

# File lib/mongo/operation/update/result.rb, line 86
def upserted_count
  upsert? ? n : 0
end
upserted_id() click to toggle source

The identifier of the inserted document if an upsert

took place.

@example Get the upserted document's identifier.

result.upserted_id

@return [ Object ] The upserted id.

@since 2.0.0

# File lib/mongo/operation/update/result.rb, line 73
def upserted_id
  return nil unless upsert?
  upsert?.first['_id']
end

Private Instance Methods

upsert?() click to toggle source
# File lib/mongo/operation/update/result.rb, line 96
def upsert?
  first[UPSERTED]
end