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

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

Overview

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

Defines custom behaviour 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'.freeze
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'.freeze

Constants inherited from Result

Result::CURSOR, Result::CURSOR_ID, Result::FIRST_BATCH, Result::N, Result::NAMESPACE, Result::NEXT_BATCH, Result::OK, Result::RESULT

Instance Attribute Summary

Attributes inherited from Result

#replies

Instance Method Summary collapse

Methods inherited from Result

#acknowledged?, #cluster_time, #cursor_id, #documents, #each, #initialize, #inspect, #multiple?, #namespace, #ok?, #operation_time, #reply, #returned_count, #successful?, #validate!, #written_count

Constructor Details

This class inherits a constructor from Mongo::Operation::Result

Instance Method Details

#bulk_resultObject

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

Since:

  • 2.0.0



90
91
92
# File 'lib/mongo/operation/update/result.rb', line 90

def bulk_result
  BulkResult.new(@replies)
end

#matched_countInteger

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

Get the number of documents matched.

Examples:

Get the matched count.

result.matched_count

Returns:

  • (Integer)

    The matched count.

Since:

  • 2.0.0



42
43
44
45
46
47
48
49
# File 'lib/mongo/operation/update/result.rb', line 42

def matched_count
  return 0 unless acknowledged?
  if upsert?
    0
  else
    n
  end
end

#modified_countInteger

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

Get the number of documents modified.

Examples:

Get the modified count.

result.modified_count

Returns:

  • (Integer)

    The modified count.

Since:

  • 2.0.0



59
60
61
62
# File 'lib/mongo/operation/update/result.rb', line 59

def modified_count
  return 0 unless acknowledged?
  first[MODIFIED]
end

#upserted_countInteger

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

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



86
87
88
# File 'lib/mongo/operation/update/result.rb', line 86

def upserted_count
  upsert? ? n : 0
end

#upserted_idObject

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

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



73
74
75
76
# File 'lib/mongo/operation/update/result.rb', line 73

def upserted_id
  return nil unless upsert?
  upsert?.first['_id']
end