API Docs for:
Show:

MongoClient Class

Module: ringo-mongodb

The MongoClient class is a MongoDB client with internal connection pooling. For most applications, you only need one MongoClient instance.

  • When invoked without arguments, the default host and port values are used. The default host is localhost and default port is 27017.

  • If the first argument starts with mongodb://, then it is considered as an URI to be used for the connection. Here's the URI format :

    mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[database][?options]]

    For a detailed specification of the URI format, please check the java driver's MongoClientURI class

  • If the first argument is not an URI, it is then used as the host and the second argument if present shall be the port.

Constructor

MongoClient

(
  • [host=localhost]
  • [port]
)

Parameters:

  • [host=localhost] String optional

    Hostname or URI

  • [port] Number optional

    Hostname or URI

Example:

 var client = mongo.MongoClient('localhost', 27017);
 var db = client.getDB('myDatabase');

Methods

close

()

Closes the underlying connector, which in turn closes all open connections. Once called, this MongoClient instance can no longer be used.

dropDatabase

()

Drops the database if it exists

getDatabaseNames

()

Gets a list of all database names present on the server.

getDB

(
  • dbname
)

Get a MongoDatabase instance

Parameters:

  • dbname String

    the database name

isLocked

() Boolean

Returns:

Boolean: true if the database is locked (read-only), false otherwise.

unlock

()

Unlocks the database, allowing the write operations to go through.

Properties

version

String

Java driver version