Module: Mongo::Operation::Specifiable

Overview

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

Since:

  • 2.0.0

Constant Summary collapse

DB_NAME =

The field for database name.

Since:

  • 2.0.0

:db_name.freeze
DELETES =

The field for deletes.

Since:

  • 2.0.0

:deletes.freeze
DELETE =

The field for delete.

Since:

  • 2.0.0

:delete.freeze
DOCUMENTS =

The field for documents.

Since:

  • 2.0.0

:documents.freeze
COLL_NAME =

The field for collection name.

Since:

  • 2.0.0

:coll_name.freeze
CURSOR_COUNT =

The field for cursor count.

Since:

  • 2.0.0

:cursor_count.freeze
CURSOR_ID =

The field for cursor id.

Since:

  • 2.0.0

:cursor_id.freeze
CURSOR_IDS =

The field for cursor ids.

Since:

  • 2.0.0

:cursor_ids.freeze
INDEX =

The field for an index.

Since:

  • 2.0.0

:index.freeze
INDEXES =

The field for multiple indexes.

Since:

  • 2.0.0

:indexes.freeze
INDEX_NAME =

The field for index names.

Since:

  • 2.0.0

:index_name.freeze
OPERATION_ID =

The operation id constant.

Since:

  • 2.1.0

:operation_id.freeze
OPTIONS =

The field for options.

Since:

  • 2.0.0

:options.freeze
READ_CONCERN =

The read concern option.

Since:

  • 2.2.0

:read_concern.freeze
MAX_TIME_MS =

The max time ms option.

Since:

  • 2.2.5

:max_time_ms.freeze
SELECTOR =

The field for a selector.

Since:

  • 2.0.0

:selector.freeze
START_TRANSACTION =

The startTransaction option

Since:

  • 2.6.0

:start_transaction.freeze
TO_RETURN =

The field for number to return.

Since:

  • 2.0.0

:to_return.freeze
UPDATES =

The field for updates.

Since:

  • 2.0.0

:updates.freeze
UPDATE =

The field for update.

Since:

  • 2.0.0

:update.freeze
USER =

The field name for a user.

Since:

  • 2.0.0

:user.freeze
USER_NAME =

The field name for user name.

Since:

  • 2.0.0

:user_name.freeze
WRITE_CONCERN =

The field name for a write concern.

Since:

  • 2.0.0

:write_concern.freeze
READ =

The field name for the read preference.

Since:

  • 2.0.0

:read.freeze
BYPASS_DOC_VALIDATION =

Whether to bypass document level validation.

Since:

  • 2.2.0

:bypass_document_validation.freeze
COLLATION =

A collation to apply to the operation.

Since:

  • 2.4.0

:collation.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#specHash (readonly)

Returns spec The specification for the operation.

Returns:

  • (Hash)

    spec The specification for the operation.

Since:

  • 2.0.0



155
156
157
# File 'lib/mongo/operation/shared/specifiable.rb', line 155

def spec
  @spec
end

Instance Method Details

#==(other) ⇒ true, false Also known as: eql?

Check equality of two specifiable operations.

Examples:

Are the operations equal?

operation == other

Parameters:

  • other (Object)

    The other operation.

Returns:

  • (true, false)

    Whether the objects are equal.

Since:

  • 2.0.0



167
168
169
170
# File 'lib/mongo/operation/shared/specifiable.rb', line 167

def ==(other)
  return false unless other.is_a?(Specifiable)
  spec == other.spec
end

#acknowledged_write?Boolean

Does the operation have an acknowledged write concern.

Examples:

Determine whether the operation has an acknowledged write.

specifiable.array_filters

Returns:

  • (Boolean)

    Whether or not the operation has an acknowledged write concern.

Since:

  • 2.5.2



580
581
582
# File 'lib/mongo/operation/shared/specifiable.rb', line 580

def acknowledged_write?
  write_concern.nil? || write_concern.acknowledged?
end

#array_filtersHash

The array filters.

Examples:

Get the array filters.

specifiable.array_filters

Returns:

  • (Hash)

    The array filters.

Since:

  • 2.5.2



557
558
559
# File 'lib/mongo/operation/shared/specifiable.rb', line 557

def array_filters
  selector[Operation::ARRAY_FILTERS] if selector
end

#bypass_document_validationtrue, false

Whether or not to bypass document level validation.

Examples:

Get the bypass_document_validation option.

specifiable.bypass_documentation_validation.

Returns:

  • (true, false)

    Whether to bypass document level validation.

Since:

  • 2.2.0



379
380
381
# File 'lib/mongo/operation/shared/specifiable.rb', line 379

def bypass_document_validation
  spec[BYPASS_DOC_VALIDATION]
end

#coll_nameString

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

Examples:

Get the collection name.

specifiable.coll_name

Returns:

  • (String)

    Collection name.

Since:

  • 2.0.0



241
242
243
# File 'lib/mongo/operation/shared/specifiable.rb', line 241

def coll_name
  spec[COLL_NAME]
end

#collationHash

The collation to apply to the operation.

Examples:

Get the collation option.

specifiable.collation.

Returns:

  • (Hash)

    The collation document.

Since:

  • 2.4.0



391
392
393
# File 'lib/mongo/operation/shared/specifiable.rb', line 391

def collation
  send(self.class::IDENTIFIER).first[COLLATION]
end

#command(server = nil) ⇒ Hash

The command.

Examples:

Get the command.

specifiable.command

Returns:

  • (Hash)

    The command.

Since:

  • 2.5.2



545
546
547
# File 'lib/mongo/operation/shared/specifiable.rb', line 545

def command(server = nil)
  selector(server)
end

#cursor_countInteger

Get the cursor count from the spec.

Examples:

Get the cursor count.

specifiable.cursor_count

Returns:

  • (Integer)

    The cursor count.

Since:

  • 2.0.0



181
182
183
# File 'lib/mongo/operation/shared/specifiable.rb', line 181

def cursor_count
  spec[CURSOR_COUNT]
end

#cursor_idInteger

The id of the cursor created on the server.

Examples:

Get the cursor id.

specifiable.cursor_id

Returns:

  • (Integer)

    The cursor id.

Since:

  • 2.0.0



253
254
255
# File 'lib/mongo/operation/shared/specifiable.rb', line 253

def cursor_id
  spec[CURSOR_ID]
end

#cursor_idsArray<Integer>

The ids of the cursors to kill from the spec.

Examples:

Get the cursor ids from the spec.

specifiable.cursor_ids

Returns:

  • (Array<Integer>)

    The cursor ids.

Since:

  • 2.0.0



265
266
267
# File 'lib/mongo/operation/shared/specifiable.rb', line 265

def cursor_ids
  spec[CURSOR_IDS]
end

#db_nameString

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

Examples:

Get the database name.

specifiable.db_name

Returns:

  • (String)

    Database name.

Since:

  • 2.0.0



193
194
195
# File 'lib/mongo/operation/shared/specifiable.rb', line 193

def db_name
  spec[DB_NAME]
end

#deleteHash

Get the delete document from the specification.

Examples:

Get the delete document.

specifiable.delete

Returns:

  • (Hash)

    The delete document.

Since:

  • 2.0.0



217
218
219
# File 'lib/mongo/operation/shared/specifiable.rb', line 217

def delete
  spec[DELETE]
end

#deletesArray<BSON::Document>

Get the deletes from the specification.

Examples:

Get the deletes.

specifiable.deletes

Returns:

  • (Array<BSON::Document>)

    The deletes.

Since:

  • 2.0.0



205
206
207
# File 'lib/mongo/operation/shared/specifiable.rb', line 205

def deletes
  spec[DELETES]
end

#documentsArray<BSON::Document>

The documents to in the specification.

Examples:

Get the documents.

specifiable.documents

Returns:

  • (Array<BSON::Document>)

    The documents.

Since:

  • 2.0.0



229
230
231
# File 'lib/mongo/operation/shared/specifiable.rb', line 229

def documents
  spec[DOCUMENTS]
end

#indexHash

Get the index from the specification.

Examples:

Get the index specification.

specifiable.index

Returns:

  • (Hash)

    The index specification.

Since:

  • 2.0.0



277
278
279
# File 'lib/mongo/operation/shared/specifiable.rb', line 277

def index
  spec[INDEX]
end

#index_nameString

Get the index name from the spec.

Examples:

Get the index name.

specifiable.index_name

Returns:

  • (String)

    The index name.

Since:

  • 2.0.0



289
290
291
# File 'lib/mongo/operation/shared/specifiable.rb', line 289

def index_name
  spec[INDEX_NAME]
end

#indexesHash

Get the indexes from the specification.

Examples:

Get the index specifications.

specifiable.indexes

Returns:

  • (Hash)

    The index specifications.

Since:

  • 2.0.0



301
302
303
# File 'lib/mongo/operation/shared/specifiable.rb', line 301

def indexes
  spec[INDEXES]
end

#initialize(spec) ⇒ Object

Create the new specifiable operation.

Examples:

Create the new specifiable operation.

Specifiable.new(spec)

Parameters:

  • spec (Hash)

    The operation specification.

See Also:

  • individual operations for the values they require in their specs.

Since:

  • 2.0.0



316
317
318
# File 'lib/mongo/operation/shared/specifiable.rb', line 316

def initialize(spec)
  @spec = spec
end

#max_time_msHash

Get the max time ms value from the spec.

Examples:

Get the max time ms.

specifiable.max_time_ms

Returns:

  • (Hash)

    The max time ms value.

Since:

  • 2.2.5



367
368
369
# File 'lib/mongo/operation/shared/specifiable.rb', line 367

def max_time_ms
  spec[MAX_TIME_MS]
end

#namespaceString

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

Examples:

Get the namespace.

specifiable.namespace

Returns:

  • (String)

    The namespace.

Since:

  • 2.1.0



509
510
511
# File 'lib/mongo/operation/shared/specifiable.rb', line 509

def namespace
  "#{db_name}.#{coll_name}"
end

#operation_idInteger

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

Examples:

Get the operation id.

specifiable.operation_id

Returns:

  • (Integer)

    The operation id.

Since:

  • 2.1.0



329
330
331
# File 'lib/mongo/operation/shared/specifiable.rb', line 329

def operation_id
  spec[OPERATION_ID]
end

#options(server = nil) ⇒ Hash

Get the options for the operation.

Examples:

Get the options.

specifiable.options

Returns:

  • (Hash)

    The options.

Since:

  • 2.0.0



341
342
343
# File 'lib/mongo/operation/shared/specifiable.rb', line 341

def options(server = nil)
  spec[OPTIONS] || {}
end

#ordered?true, false

Whether the operation is ordered.

Examples:

Get the ordered value, true is the default.

specifiable.ordered?

Returns:

  • (true, false)

    Whether the operation is ordered.

Since:

  • 2.1.0



497
498
499
# File 'lib/mongo/operation/shared/specifiable.rb', line 497

def ordered?
  !!(@spec.fetch(:ordered, true))
end

#readMongo::ServerSelector

The read preference for this operation.

Examples:

Get the read preference.

specifiable.read

Returns:

Since:

  • 2.0.0



485
486
487
# File 'lib/mongo/operation/shared/specifiable.rb', line 485

def read
  @read ||= ServerSelector.get(spec[READ]) if spec[READ]
end

#read_concernHash

Note:

The document may include afterClusterTime.

Get the read concern document from the spec.

Examples:

Get the read concern.

specifiable.read_concern

Returns:

  • (Hash)

    The read concern document.

Since:

  • 2.2.0



355
356
357
# File 'lib/mongo/operation/shared/specifiable.rb', line 355

def read_concern
  spec[READ_CONCERN]
end

#selector(server = nil) ⇒ Hash

The selector for from the specification.

Examples:

Get a selector specification.

specifiable.selector.

Returns:

  • (Hash)

    The selector spec.

Since:

  • 2.0.0



403
404
405
# File 'lib/mongo/operation/shared/specifiable.rb', line 403

def selector(server = nil)
  spec[SELECTOR]
end

#sessionSession

The session to use for the operation.

Examples:

Get the session.

specifiable.session

Returns:

Since:

  • 2.5.0



521
522
523
# File 'lib/mongo/operation/shared/specifiable.rb', line 521

def session
  @spec[:session]
end

#start_transactionBoolean

The startTransaction option.

Examples:

Get the startTransaction option.

specifiable.start_transaction

Returns:

  • (Boolean)

    The startTransaction option.

Since:

  • 2.0.0



568
569
570
# File 'lib/mongo/operation/shared/specifiable.rb', line 568

def start_transaction
  @spec[START_TRANSACTION]
end

#to_returnInteger

The number of documents to request from the server.

Examples:

Get the to return value from the spec.

specifiable.to_return

Returns:

  • (Integer)

    The number of documents to return.

Since:

  • 2.0.0



415
416
417
# File 'lib/mongo/operation/shared/specifiable.rb', line 415

def to_return
  spec[TO_RETURN]
end

#txn_numInteger

The transaction number for the operation.

Examples:

Get the transaction number.

specifiable.txn_num

Returns:

  • (Integer)

    The transaction number.

Since:

  • 2.5.0



533
534
535
# File 'lib/mongo/operation/shared/specifiable.rb', line 533

def txn_num
  @spec[:txn_num]
end

#updateHash

The update document from the spec.

Examples:

Get the update document.

Returns:

  • (Hash)

    The update document.

Since:

  • 2.0.0



437
438
439
# File 'lib/mongo/operation/shared/specifiable.rb', line 437

def update
  spec[UPDATE]
end

#updatesArray<BSON::Document>

The update documents from the spec.

Examples:

Get the update documents.

Returns:

  • (Array<BSON::Document>)

    The update documents.

Since:

  • 2.0.0



426
427
428
# File 'lib/mongo/operation/shared/specifiable.rb', line 426

def updates
  spec[UPDATES]
end

#userAuth::User

The user for user related operations.

Examples:

Get the user.

specifiable.user

Returns:

Since:

  • 2.0.0



449
450
451
# File 'lib/mongo/operation/shared/specifiable.rb', line 449

def user
  spec[USER]
end

#user_nameString

The user name from the specification.

Examples:

Get the user name.

specifiable.user_name

Returns:

  • (String)

    The user name.

Since:

  • 2.0.



461
462
463
# File 'lib/mongo/operation/shared/specifiable.rb', line 461

def user_name
  spec[USER_NAME]
end

#write_concernMongo::WriteConcern

The write concern to use for this operation.

Examples:

Get the write concern.

specifiable.write_concern

Returns:

Since:

  • 2.0.0



473
474
475
# File 'lib/mongo/operation/shared/specifiable.rb', line 473

def write_concern
  @spec[WRITE_CONCERN]
end