Mongo_Db クラス

イントロダクション

The Mongo_Db class provides methods to interact with Mongo databases.

Besides providing the normal insert, select, delete and update functionality it has some management methods to help you with database utility operations.

設定

For every Mongo database connection there must be a config in mongo array in app/config/db.php. Configuration options and explanation are listed below. Every config requires to contain a hostname and database name.

パラメータ Required 説明
hostname string yes the hostname
database string yes the database name
port number no the port to use in the connection
replicaset string no the name of the replicaset to use for the connection
username string no username used for authentication, ignored if no password has been set
password string no password used for authentication, ignored if no password has been set

Example config:

// Inside app/config/db.php

		'mongo' => array(
			// This group is used when no instance name has been provided.
			'default' => array(
				'hostname'   => 'localhost',
				'database'   => 'mongo_fuel',
			),

			// List your own groups below.
			'my_mongo_connection' => array(
				'hostname'   => 'localhost',
				'database'   => 'my_db',
				'replicaset' => 'replica',
				'username'   => 'user',
				'password'   => 'p@s$w0rD',
			),
		),
	

Once you have your setting in place you can start using MongoDB.

In order to use MongoDB this must be available on your server. To see if you have mongo support on you server, look for the Mongo section in your phpinfo() or ask you hosting company.