\Hazaar\MongoDB
Adapter
MongoDB database access class

The MongoDB class helps streamline access to MongoDB database servers by providing configuration methods and helper methods for executing server-side code.

It is serializable and as such is safe to store in a session or other cache mechanism such as the Hazaar MVC Cache module.

Tags

Since

1.0.0

Extends
\MongoDB
Summary
Methods Properties Constants
No constants
Properties
Static
$config
$config
$connection
$connection
$current_config
$current_config
Methods
__call()
__call($method, $args) : mixed
Magic method for executing functions on the MongoDB node as methods of the object.

Tags

Since

1.0.0

Parameters

$method

No description

$args

No description

Returns

mixed

Returns the result from the server-side function call.

__construct()
__construct($args = Array ( ) )

Parameters

$args

No description

__sleep()
__sleep()
__wakeup()
__wakeup()
call()
call($method, $args = Array ( ) ) : mixed
Method for executing server-side functions on the MongoDB node.

Tags

Since

1.0.0

Parameters

$method

No description

$args

No description

Returns

mixed

Returns the result from the server-side function call.

Static
configure()
configure($args, $default = true)
Configure the Hazaar\MongoDB object with defaults.

This means configuration parameters can be omitted from the constructor. These defaults can also be overridden by specifying parameters in the constructor.

Options:

  • hosts – Array or comma delimited string of hosts to connect to.
  • slaveok – Boolean specifying that it’s ok to query slaves
  • replset – String of the name of the replica set to use.

Example

$config = array( ‘hosts’ => ‘mongodb.mydomain.com’, ‘slaveok’ => false, ‘replset’ => ‘myReplSet’ ); Hazaar\MongoDB\Adapter::configure($config);

Tags

Since

1.0.0

Parameters

$argsArray

Array of configuration options.

$defaultboolean

Use this config array as the default configuration. True by default.

connect()
connect()
getDocument()
getDocument($collection, $criteria = Array ( ) , $fields = Array ( ) ) : MongoDB\Document
Retrieve a document object from the database.

This method is useful when you want to work with a single document using the enhanced Hazaar\MongoDB\Document class.

Tags

Since

1.0.0

Parameters

$collectionstring

The name of the collection to search.

$criteriaArray

An array of search criteria supported by MongoDB.

$fieldsArray

An array of field names to return.

Returns

\Hazaar\MongoDB\MongoDB\Document

A new document object.

storeFunction()
storeFunction($name, $code, $args = Array ( ) ) : boolean
Stores or updates JavaScript code as a server-side function on a MongoDB node.

Tags

Since

1.0.0

Parameters

$namestring

The name of the function

$codestring

The javascript code to store

$argsArray

Function argument definition

Returns

boolean

Status of save command.