Method: Mongo::Database::View#list_collections

Defined in:
lib/mongo/database/view.rb

#list_collections(options = {}) ⇒ Array<Hash>

Note:

The set of collections returned, and the schema of the information hash per collection, depends on the MongoDB server version that fulfills the request.

Get info on all the collections in the database.

Examples:

Get info on each collection.

database.list_collections

Parameters:

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

Options Hash (options):

  • :filter (Hash)

    A filter on the collections returned.

  • :name_only (true, false)

    Indicates whether command should return just collection/view names and type or return both the name and other information

  • :authorized_collections (true, false)

    A flag, when set to true and used with nameOnly: true, that allows a user without the required privilege to run the command when access control is enforced

    See mongodb.com/docs/manual/reference/command/listCollections/ for more information and usage.

  • :session (Session)

    The session to use.

  • :deserialize_as_bson (Boolean)

    Whether to deserialize this message using BSON types instead of native Ruby types wherever possible.

Returns:

  • (Array<Hash>)

    Info for each collection in the database.

Since:

  • 2.0.5



129
130
131
132
# File 'lib/mongo/database/view.rb', line 129

def list_collections(options = {})
  session = client.get_session(options)
  collections_info(session, ServerSelector.primary, options)
end