Method: Mongo::Collection#drop

Defined in:
lib/mongo/collection.rb

#drop(opts = {}) ⇒ Result

Note:

An error returned if the collection doesn’t exist is suppressed.

Drop the collection. Will also drop all indexes associated with the collection, as well as associated queryable encryption collections.

Examples:

Drop the collection.

collection.drop

Parameters:

  • opts (Hash) (defaults to: {})

    The options for the drop operation.

  • options (Hash)

    a customizable set of options

Options Hash (opts):

  • :session (Session)

    The session to use for the operation.

  • :write_concern (Hash)

    The write concern options.

  • :encrypted_fields (Hash | nil)

    Encrypted fields hash that was provided to ‘create` collection helper.

Returns:

  • (Result)

    The result of the command.

Since:

  • 2.0.0



454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
# File 'lib/mongo/collection.rb', line 454

def drop(opts = {})
  client.with_session(opts) do |session|
    maybe_drop_emm_collections(opts[:encrypted_fields], client, session) do
      temp_write_concern = write_concern
      write_concern = if opts[:write_concern]
        WriteConcern.get(opts[:write_concern])
      else
        temp_write_concern
      end
      context = Operation::Context.new(
        client: client,
        session: session,
        operation_timeouts: operation_timeouts(opts)
      )
      operation = Operation::Drop.new({
        selector: { :drop => name },
        db_name: database.name,
        write_concern: write_concern,
        session: session,
      })
      do_drop(operation, session, context)
    end
  end
end