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

Inherits:
Result
  • Object
show all
Includes:
Result::UseLegacyErrorParser
Defined in:
build/ruby-driver-master/lib/mongo/operation/update/legacy/result.rb

Overview

Defines custom behavior of results for an update on server version <= 2.4.

Since:

  • 2.0.0

Constant Summary collapse

UPDATED_EXISTING =

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.

Whether an existing document was updated.

Since:

  • 2.0.0

'updatedExisting'.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

#connection_description, #replies

Instance Method Summary collapse

Methods included from Result::UseLegacyErrorParser

#parser

Methods inherited from Result

#acknowledged?, #cluster_time, #cursor_id, #documents, #each, #error, #initialize, #inspect, #labels, #namespace, #ok?, #operation_time, #reply, #returned_count, #snapshot_timestamp, #successful?, #topology_version, #validate!, #write_concern_error?, #written_count

Constructor Details

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

Instance Method Details

#matched_countInteger

Get the number of documents matched.

Examples:

Get the matched count.

result.matched_count

Returns:

  • (Integer)

    The matched count.

Since:

  • 2.0.0



52
53
54
55
56
57
58
59
# File 'build/ruby-driver-master/lib/mongo/operation/update/legacy/result.rb', line 52

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

#modified_countnil

Get the number of documents modified.

Examples:

Get the modified count.

result.modified_count

Returns:

  • (nil)

    Always omitted for legacy versions.

Since:

  • 2.0.0



70
# File 'build/ruby-driver-master/lib/mongo/operation/update/legacy/result.rb', line 70

def modified_count; end

#upserted_countInteger

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



95
96
97
# File 'build/ruby-driver-master/lib/mongo/operation/update/legacy/result.rb', line 95

def upserted_count
  upsert? ? n : 0
end

#upserted_idObject

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



82
83
84
# File 'build/ruby-driver-master/lib/mongo/operation/update/legacy/result.rb', line 82

def upserted_id
  first[UPSERTED] if upsert?
end