module Mongo::Operation::Specifiable

This module contains common functionality for convenience methods getting various values from the spec.

@since 2.0.0 @api private

Constants

BYPASS_DOC_VALIDATION

Whether to bypass document level validation.

@since 2.2.0

COLLATION

A collation to apply to the operation.

@since 2.4.0

COLL_NAME

The field for collection name.

@since 2.0.0

CURSOR_COUNT

The field for cursor count.

@since 2.0.0

CURSOR_ID

The field for cursor id.

@since 2.0.0

DB_NAME

The field for database name.

@since 2.0.0

DELETE

The field for delete.

@since 2.0.0

DELETES

The field for deletes.

@since 2.0.0

DOCUMENTS

The field for documents.

@since 2.0.0

INDEX

The field for an index.

@since 2.0.0

INDEXES

The field for multiple indexes.

@since 2.0.0

INDEX_NAME

The field for index names.

@since 2.0.0

MAX_TIME_MS

The max time ms option.

@since 2.2.5

OPERATION_ID

The operation id constant.

@since 2.1.0

OPTIONS

The field for options.

@since 2.0.0

READ

The field name for the read preference.

@since 2.0.0

READ_CONCERN

The read concern option.

@since 2.2.0

SELECTOR

The field for a selector.

@since 2.0.0

TO_RETURN

The field for number to return.

@since 2.0.0

UPDATE

The field for update.

@since 2.0.0

UPDATES

The field for updates.

@since 2.0.0

USER

The field name for a user.

@since 2.0.0

USER_NAME

The field name for user name.

@since 2.0.0

WRITE_CONCERN

The field name for a write concern.

@since 2.0.0

Attributes

spec[R]

@return [ Hash ] spec The specification for the operation.

Public Class Methods

new(spec) click to toggle source

Create the new specifiable operation.

@example Create the new specifiable operation.

Specifiable.new(spec)

@param [ Hash ] spec The operation specification.

@see The individual operations for the values they require in their

specs.

@since 2.0.0

# File lib/mongo/operation/shared/specifiable.rb, line 298
def initialize(spec)
  @spec = spec
end

Public Instance Methods

==(other) click to toggle source

Check equality of two specifiable operations.

@example Are the operations equal?

operation == other

@param [ Object ] other The other operation.

@return [ true, false ] Whether the objects are equal.

@since 2.0.0

# File lib/mongo/operation/shared/specifiable.rb, line 161
def ==(other)
  return false unless other.is_a?(Specifiable)
  spec == other.spec
end
Also aliased as: eql?
acknowledged_write?() click to toggle source

Does the operation have an acknowledged write concern.

@example Determine whether the operation has an acknowledged write.

specifiable.array_filters

@return [ Boolean ] Whether or not the operation has an acknowledged write concern.

@since 2.5.2

# File lib/mongo/operation/shared/specifiable.rb, line 552
def acknowledged_write?
  write_concern.nil? || write_concern.acknowledged?
end
apply_collation(selector, connection, collation) click to toggle source
# File lib/mongo/operation/shared/specifiable.rb, line 556
def apply_collation(selector, connection, collation)
  if collation
    unless connection.features.collation_enabled?
      raise Error::UnsupportedCollation
    end
    selector = selector.merge(collation: collation)
  end
  selector
end
array_filters(connection) click to toggle source

The array filters.

@param [ Server::Connection ] connection The connection that the

operation will be executed on.

@return [ Hash | nil ] The array filters.

@since 2.5.2

# File lib/mongo/operation/shared/specifiable.rb, line 539
def array_filters(connection)
  sel = selector(connection)
  sel[Operation::ARRAY_FILTERS] if sel
end
bypass_document_validation() click to toggle source

Whether or not to bypass document level validation.

@example Get the bypass_document_validation option.

specifiable.bypass_documentation_validation.

@return [ true, false ] Whether to bypass document level validation.

@since 2.2.0

# File lib/mongo/operation/shared/specifiable.rb, line 361
def bypass_document_validation
  spec[BYPASS_DOC_VALIDATION]
end
coll_name() click to toggle source

The name of the collection to which the operation should be sent.

@example Get the collection name.

specifiable.coll_name

@return [ String ] Collection name.

@since 2.0.0

# File lib/mongo/operation/shared/specifiable.rb, line 235
def coll_name
  spec.fetch(COLL_NAME)
end
collation() click to toggle source

The collation to apply to the operation.

@example Get the collation option.

specifiable.collation.

@return [ Hash ] The collation document.

@since 2.4.0

# File lib/mongo/operation/shared/specifiable.rb, line 373
def collation
  send(self.class::IDENTIFIER).first[COLLATION]
end
command(connection) click to toggle source

The command.

@return [ Hash ] The command.

@since 2.5.2

# File lib/mongo/operation/shared/specifiable.rb, line 527
def command(connection)
  selector(connection)
end
cursor_count() click to toggle source

Get the cursor count from the spec.

@example Get the cursor count.

specifiable.cursor_count

@return [ Integer ] The cursor count.

@since 2.0.0

# File lib/mongo/operation/shared/specifiable.rb, line 175
def cursor_count
  spec[CURSOR_COUNT]
end
cursor_id() click to toggle source

The id of the cursor created on the server.

@example Get the cursor id.

specifiable.cursor_id

@return [ Integer ] The cursor id.

@since 2.0.0

# File lib/mongo/operation/shared/specifiable.rb, line 247
def cursor_id
  spec[CURSOR_ID]
end
db_name() click to toggle source

The name of the database to which the operation should be sent.

@example Get the database name.

specifiable.db_name

@return [ String ] Database name.

@since 2.0.0

# File lib/mongo/operation/shared/specifiable.rb, line 187
def db_name
  spec[DB_NAME]
end
delete() click to toggle source

Get the delete document from the specification.

@example Get the delete document.

specifiable.delete

@return [ Hash ] The delete document.

@since 2.0.0

# File lib/mongo/operation/shared/specifiable.rb, line 211
def delete
  spec[DELETE]
end
deletes() click to toggle source

Get the deletes from the specification.

@example Get the deletes.

specifiable.deletes

@return [ Array<BSON::Document> ] The deletes.

@since 2.0.0

# File lib/mongo/operation/shared/specifiable.rb, line 199
def deletes
  spec[DELETES]
end
documents() click to toggle source

The documents to in the specification.

@example Get the documents.

specifiable.documents

@return [ Array<BSON::Document> ] The documents.

@since 2.0.0

# File lib/mongo/operation/shared/specifiable.rb, line 223
def documents
  spec[DOCUMENTS]
end
eql?(other)
Alias for: ==
index() click to toggle source

Get the index from the specification.

@example Get the index specification.

specifiable.index

@return [ Hash ] The index specification.

@since 2.0.0

# File lib/mongo/operation/shared/specifiable.rb, line 259
def index
  spec[INDEX]
end
index_name() click to toggle source

Get the index name from the spec.

@example Get the index name.

specifiable.index_name

@return [ String ] The index name.

@since 2.0.0

# File lib/mongo/operation/shared/specifiable.rb, line 271
def index_name
  spec[INDEX_NAME]
end
indexes() click to toggle source

Get the indexes from the specification.

@example Get the index specifications.

specifiable.indexes

@return [ Hash ] The index specifications.

@since 2.0.0

# File lib/mongo/operation/shared/specifiable.rb, line 283
def indexes
  spec[INDEXES]
end
max_time_ms() click to toggle source

Get the max time ms value from the spec.

@example Get the max time ms.

specifiable.max_time_ms

@return [ Hash ] The max time ms value.

@since 2.2.5

# File lib/mongo/operation/shared/specifiable.rb, line 349
def max_time_ms
  spec[MAX_TIME_MS]
end
namespace() click to toggle source

The namespace, consisting of the db name and collection name.

@example Get the namespace.

specifiable.namespace

@return [ String ] The namespace.

@since 2.1.0

# File lib/mongo/operation/shared/specifiable.rb, line 494
def namespace
  "#{db_name}.#{coll_name}"
end
operation_id() click to toggle source

Get the operation id for the operation. Used for linking operations in monitoring.

@example Get the operation id.

specifiable.operation_id

@return [ Integer ] The operation id.

@since 2.1.0

# File lib/mongo/operation/shared/specifiable.rb, line 311
def operation_id
  spec[OPERATION_ID]
end
options(connection) click to toggle source

Get the options for executing the operation on a particular connection.

@param [ Server::Connection ] connection The connection that the

operation will be executed on.

@return [ Hash ] The options.

@since 2.0.0

# File lib/mongo/operation/shared/specifiable.rb, line 323
def options(connection)
  spec[OPTIONS] || {}
end
ordered?() click to toggle source

Whether the operation is ordered.

@example Get the ordered value, true is the default.

specifiable.ordered?

@return [ true, false ] Whether the operation is ordered.

@since 2.1.0

# File lib/mongo/operation/shared/specifiable.rb, line 482
def ordered?
  !!(@spec.fetch(:ordered, true))
end
read() click to toggle source

The read preference for this operation.

@example Get the read preference.

specifiable.read

@return [ Mongo::ServerSelector ] The read preference.

@since 2.0.0

# File lib/mongo/operation/shared/specifiable.rb, line 468
def read
  @read ||= begin
    ServerSelector.get(spec[READ]) if spec[READ]
  end
end
read_concern() click to toggle source

Get the read concern document from the spec.

@note The document may include afterClusterTime.

@example Get the read concern.

specifiable.read_concern

@return [ Hash ] The read concern document.

@since 2.2.0

# File lib/mongo/operation/shared/specifiable.rb, line 337
def read_concern
  spec[READ_CONCERN]
end
selector(connection) click to toggle source

The selector from the specification for execution on a particular connection.

@param [ Server::Connection ] connection The connection that the

operation will be executed on.

@return [ Hash ] The selector spec.

@since 2.0.0

# File lib/mongo/operation/shared/specifiable.rb, line 386
def selector(connection)
  spec[SELECTOR]
end
session() click to toggle source

The session to use for the operation.

@example Get the session.

specifiable.session

@return [ Session ] The session.

@since 2.5.0

# File lib/mongo/operation/shared/specifiable.rb, line 506
def session
  @spec[:session]
end
to_return() click to toggle source

The number of documents to request from the server.

@example Get the to return value from the spec.

specifiable.to_return

@return [ Integer ] The number of documents to return.

@since 2.0.0

# File lib/mongo/operation/shared/specifiable.rb, line 398
def to_return
  spec[TO_RETURN]
end
txn_num() click to toggle source

The transaction number for the operation.

@example Get the transaction number.

specifiable.txn_num

@return [ Integer ] The transaction number.

@since 2.5.0

# File lib/mongo/operation/shared/specifiable.rb, line 518
def txn_num
  @spec[:txn_num]
end
update() click to toggle source

The update document from the spec.

@example Get the update document.

@return [ Hash ] The update document.

@since 2.0.0

# File lib/mongo/operation/shared/specifiable.rb, line 420
def update
  spec[UPDATE]
end
updates() click to toggle source

The update documents from the spec.

@example Get the update documents.

@return [ Array<BSON::Document> ] The update documents.

@since 2.0.0

# File lib/mongo/operation/shared/specifiable.rb, line 409
def updates
  spec[UPDATES]
end
user() click to toggle source

The user for user related operations.

@example Get the user.

specifiable.user

@return [ Auth::User ] The user.

@since 2.0.0

# File lib/mongo/operation/shared/specifiable.rb, line 432
def user
  spec[USER]
end
user_name() click to toggle source

The user name from the specification.

@example Get the user name.

specifiable.user_name

@return [ String ] The user name.

@since 2.0.

# File lib/mongo/operation/shared/specifiable.rb, line 444
def user_name
  spec[USER_NAME]
end
write_concern() click to toggle source

The write concern to use for this operation.

@example Get the write concern.

specifiable.write_concern

@return [ Mongo::WriteConcern ] The write concern.

@since 2.0.0

# File lib/mongo/operation/shared/specifiable.rb, line 456
def write_concern
  @spec[WRITE_CONCERN]
end