Class: Mongo::Operation::Update::Result

Inherits:
Operation::Result
  • Object
show all
Defined in:
lib/mongo/operation/update/result.rb

Overview

Defines custom behavior of results for an update.

Since:

  • 2.0.0

Constant Summary collapse

MODIFIED =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

The number of modified docs field in the result.

Since:

  • 2.0.0

'nModified'
UPSERTED =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

The upserted docs field in the result.

Since:

  • 2.0.0

'upserted'

Instance Method Summary collapse

Instance Method Details

#bulk_result ⇒ Object

Since:

  • 2.0.0



101
102
103
# File 'lib/mongo/operation/update/result.rb', line 101

def bulk_result
  BulkResult.new(@replies, connection_description)
end

#matched_count ⇒ Integer

Get the number of documents matched.

Examples:

Get the matched count.

result.matched_count

Returns:

  • (Integer) —

    The matched count.

Since:

  • 2.0.0



46
47
48
49
50
51
52
53
54
# File 'lib/mongo/operation/update/result.rb', line 46

def matched_count
  return 0 unless acknowledged?

  if upsert?
    0
  else
    n
  end
end

#modified_count ⇒ Integer

Get the number of documents modified.

Examples:

Get the modified count.

result.modified_count

Returns:

  • (Integer) —

    The modified count.

Since:

  • 2.0.0



65
66
67
68
69
# File 'lib/mongo/operation/update/result.rb', line 65

def modified_count
  return 0 unless acknowledged?

  first[MODIFIED]
end

#upserted_count ⇒ Integer

Returns the number of documents upserted.

Examples:

Get the number of upserted documents.

result.upserted_count

Returns:

  • (Integer) —

    The number upserted.

Since:

  • 2.4.2



96
97
98
# File 'lib/mongo/operation/update/result.rb', line 96

def upserted_count
  upsert? ? n : 0
end

#upserted_id ⇒ Object

The identifier of the inserted document if an upsert took place.

Examples:

Get the upserted document's identifier.

result.upserted_id

Returns:

  • (Object) —

    The upserted id.

Since:

  • 2.0.0



81
82
83
84
85
# File 'lib/mongo/operation/update/result.rb', line 81

def upserted_id
  return nil unless upsert?

  upsert?.first['_id']
end