Class Moped::Database
In: lib/moped/database.rb
Parent: Object

The class for interacting with a MongoDB database. One only interacts with this class indirectly through a session.

@since 1.0.0

Methods

[]   collection_names   collections   command   drop   login   logout   new  

Included Modules

Readable

Attributes

name  [R]  @!attribute name
  @return [ String ] The name of the database.

@!attribute session

  @return [ Session ] The database session.
session  [R]  @!attribute name
  @return [ String ] The name of the database.

@!attribute session

  @return [ Session ] The database session.

Public Class methods

Initialize the database.

@example Initialize a database object.

  Database.new(session, :artists)

@param [ Session ] session The session. @param [ String, Symbol ] name The name of the database.

@since 1.0.0

Public Instance methods

Get a collection by the provided name.

@example Get a collection.

  session[:users]

@param [ Symbol, String ] collection The collection name.

@return [ Collection ] An instance of the collection.

@since 1.0.0

Get all non-system collection names from the database, this excludes indexes.

@example Get all the collection names.

  database.collection_names

@return [ Array<String> ] The names of all collections.

@since 1.0.0

Get all non-system collections from the database.

@example Get all the collections.

  database.collections

@return [ Array<Collection> ] All the collections.

@since 1.0.0

Run command on the database.

@example Run a command.

  db.command(ismaster: 1)
  # => { "master" => true, hosts: [] }

@param [ Hash ] command The command to run.

@return [ Hash ] the result of the command.

@since 1.0.0

Drop the database.

@example Drop the database.

  database.drop

@return [ nil ] nil.

@since 1.0.0

Log in with username and password on the current database.

@example Authenticate against the database.

  session.login("user", "pass")

@param [ String ] username The username. @param [ String ] password The password.

@since 1.0.0

Log out from the current database.

@example Logout from the current database.

  session.logout

@since 1.0.0

[Validate]