Docs Menu
Docs Home
/ / /
Ruby MongoDB Driver


On this page

  • List Collections
  • Arbitrary Comands
  • Drop Database

The driver provides various helpers on database objects for executing commands, getting collection lists, and administrative tasks.

To get a list of collections or collection names for a database, use collections and collection_names, respectively.

client =[ '' ], database: 'music')
database = client.database
database.collections # Returns an array of Collection objects.
database.collection_names # Returns an array of collection names as strings.

To execute any command on the database, use the command method.

client =[ '' ], database: 'music')
database = client.database
result = database.command(:ping => 1)
result.first # Returns the BSON::Document returned from the server.


Specifying server API version as a client option and also specifying any of the respective command parameters to the command method (i.e. the apiVersion, apiStrict and apiDeprecationErrors command parameters) at the same time is not allowed and will produce an error.

To drop a database, use the drop method.

client =[ '' ], :database => 'music')


Schema Operations