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 (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



439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
# File 'lib/mongo/collection.rb', line 439

def drop(opts = {})
  client.send(: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 = Operation::Drop.new({
        selector: { :drop => name },
        db_name: database.name,
        write_concern: write_concern,
        session: session,
      })
      do_drop(operation, session, context)
    end
  end
end