java.lang.Object | |
↳ | com.mongodb.DB |
Known Direct Subclasses |
an abstract class that represents a logical database on a server
Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
_readOnly |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Adds the give option
| |||||||||||
Adds a new user for this db
| |||||||||||
Adds a new user for this db
| |||||||||||
Authenticates to db with the given name and password
| |||||||||||
Authenticates to db with the given name and password
| |||||||||||
Checks to see if a collection by name %lt;name> exists.
| |||||||||||
Executes a database command.
| |||||||||||
Executes a database command.
| |||||||||||
Executes a database command.
| |||||||||||
Executes a database command.
| |||||||||||
Executes a database command.
| |||||||||||
Creates a collection with a given name and options.
| |||||||||||
evaluates a function on the database.
| |||||||||||
Drops this database.
| |||||||||||
For testing purposes only - this method forces an error to help test error handling
| |||||||||||
Gets a collection with a given name.
| |||||||||||
Returns a collection matching a given string.
| |||||||||||
Returns a set containing the names of all collections in this database.
| |||||||||||
@return
| |||||||||||
Gets the the error (if there is one) from the previous operation on this connection.
| |||||||||||
Gets the Mongo instance
| |||||||||||
Returns the name of this database.
| |||||||||||
Gets the query options
| |||||||||||
Returns the last error that occurred since start of database or a call to
resetError()
The return object will look like
{ err : errorMessage, nPrev : countOpsBack, ok : 1 }The value for errorMessage will be null of no error has occurred, otherwise the error message. | |||||||||||
Gets the default read preference
| |||||||||||
Gets another database on same server
| |||||||||||
Returns the result of "dbstats" command
| |||||||||||
Gets the write concern for this database.
| |||||||||||
Returns true if a user has been authenticated
| |||||||||||
Removes a user for this db
| |||||||||||
ends the current "consistent request"
| |||||||||||
ensure that a connection is assigned to the current "consistent request" (from primary pool, if connected to a replica set)
| |||||||||||
starts a new "consistent request".
| |||||||||||
Resets the error memory for this database.
| |||||||||||
Resets the query options
| |||||||||||
Sets the query options
| |||||||||||
Makes this database read-only.
| |||||||||||
Sets the read preference for this database.
| |||||||||||
Sets the write concern for this database.
| |||||||||||
This method is deprecated.
Replaced with ReadPreference.SECONDARY
| |||||||||||
Returns the name of this database.
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Returns the collection represented by the string <dbName>.<collectionName>.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
|
Adds the give option
Adds a new user for this db
readOnly | if true, user will only be able to read |
---|
Authenticates to db with the given name and password
username | name of user for this database |
---|---|
passwd | password of user for this database |
MongoException | |
MongoException |
Authenticates to db with the given name and password
username | name of user for this database |
---|---|
passwd | password of user for this database |
MongoException | if authentication failed due to invalid user/pass, or other exceptions like I/O |
---|
Checks to see if a collection by name %lt;name> exists.
collectionName | The collection to test for existence |
---|
Executes a database command.
This method constructs a simple dbobject and calls command(com.mongodb.DBObject)
cmd | command to execute |
---|
MongoException |
---|
MongoException |
---|
Executes a database command.
cmd | dbobject representing the command to execute |
---|---|
options | query options to use |
readPrefs | ReadPreferences for this command (nodes selection is the biggest part of this) |
MongoException |
---|
Executes a database command.
This method constructs a simple dbobject and calls command(com.mongodb.DBObject, int)
cmd | command to execute |
---|---|
options | query options to use |
MongoException |
---|
Executes a database command.
This method calls command(com.mongodb.DBObject, int)
with 0 as query option.
cmd | dbobject representing the command to execute |
---|
MongoException | |
MongoException |
Executes a database command.
cmd | dbobject representing the command to execute |
---|---|
options | query options to use |
MongoException |
---|
Creates a collection with a given name and options. If the collection does not exist, a new collection is created. Note that if the options parameter is null, the creation will be deferred to when the collection is written to. Possible options:
name | the name of the collection to return |
---|---|
options | options |
evaluates a function on the database. This is useful if you need to touch a lot of data lightly, in which case network transfer could be a bottleneck.
code | the function in javascript code |
---|---|
args | arguments to be passed to the function |
MongoException |
---|
Drops this database. Removes all data on disk. Use with caution.
MongoException |
---|
calls doEval(java.lang.String, java.lang.Object[])
.
If the command is successful, the "retval" field is extracted and returned.
Otherwise an exception is thrown.
code | the function in javascript code |
---|---|
args | arguments to be passed to the function |
MongoException |
---|
For testing purposes only - this method forces an error to help test error handling
MongoException |
---|
Gets a collection with a given name. If the collection does not exist, a new collection is created.
name | the name of the collection to return |
---|
Returns a collection matching a given string.
s | the name of the collection |
---|
Returns a set containing the names of all collections in this database.
MongoException |
---|
MongoException |
---|
@return
concern | the concern associated with "getLastError" call |
---|
MongoException |
---|
Gets the the error (if there is one) from the previous operation on this connection. The result of this command will look like
{ "err" : errorMessage , "ok" : 1.0 }The value for errorMessage will be null if no error occurred, or a description otherwise. Important note: when calling this method directly, it is undefined which connection "getLastError" is called on. You may need to explicitly use a "consistent Request", see
requestStart()
For most purposes it is better not to call this method directly but instead use WriteConcern
MongoException |
---|
Gets the query options
Returns the last error that occurred since start of database or a call to resetError()
The return object will look like
{ err : errorMessage, nPrev : countOpsBack, ok : 1 }The value for errorMessage will be null of no error has occurred, otherwise the error message. The value of countOpsBack will be the number of operations since the error occurred. Care must be taken to ensure that calls to getPreviousError go to the same connection as that of the previous operation. See
requestStart()
for more information.MongoException |
---|
Gets another database on same server
name | name of the database |
---|
Returns true if a user has been authenticated
ends the current "consistent request"
ensure that a connection is assigned to the current "consistent request" (from primary pool, if connected to a replica set)
starts a new "consistent request". Following this call and until requestDone() is called, all db operations should use the same underlying connection. This is useful to ensure that operations happen in a certain order with predictable results.
Resets the error memory for this database.
Used to clear all errors such that getPreviousError()
will return no error.
MongoException |
---|
Resets the query options
Sets the query options
Makes this database read-only. Important note: this is a convenience setting that is only known on the client side and not persisted.
b | if the database should be read-only |
---|
Sets the read preference for this database. Will be used as default for
reads from any collection in this database. See the
documentation for ReadPreference
for more information.
preference | Read Preference to use |
---|
Sets the write concern for this database. It Will be used for
writes to any collection in this database. See the
documentation for WriteConcern
for more information.
concern | write concern to use |
---|
This method is deprecated.
Replaced with ReadPreference.SECONDARY
Makes it possible to execute "read" queries on a slave node
Returns the collection represented by the string <dbName>.<collectionName>.
name | the name of the collection |
---|