Class MongodbSource

Description

MongoDB Source

Located in /datasources/mongodb_source.php (line 35)

DboSource
   |
   --MongodbSource
Variable Summary
array $columns
boolean $connected
array $_baseConfig
resource $_db
mixed $_startTime
Method Summary
void __construct ([array $config = array()], [bool $autoConnect = false])
void __destruct ()
void begin ()
array calculate ( &$Model, Model $Model)
boolean close ()
void commit ()
boolean connect ()
boolean create ( &$Model, [array $fields = null], [array $values = null], Model $Model)
void createConnectionName (array $config, string $version)
void createSchema (mixed $schema, [mixed $tableName = null])
boolean delete ( &$Model, [array $conditions = null], Model $Model)
void deriveSchemaFromData (mixed $Model, [array $data = array()])
array describe ( &$Model, [ $field = null], Model $Model)
boolean disconnect ()
void distinct ( &$Model, [array $keys = array()], [array $params = array()], mixed $Model)
void dropSchema (mixed $schema, [mixed $tableName = null])
void ensureIndex ( &$Model, [array $keys = array()], [array $params = array()], mixed $Model)
void execute (mixed $query, [array $params = array()])
mixed getMongoCollection ( &$Model)
mixed getMongoDb ()
void group ( &$Model, [array $params = array()], mixed $Model)
void insertMulti (string $table, string $fields, array $values)
boolean isConnected ()
void isInterfaceSupported (mixed $interface)
array listSources ([array $data = null])
void logQuery (mixed $query, [array $args = array()])
mixed mapReduce (mixed $query, [integer $timeout = null])
string name (string $name)
void query (mixed $query, [array $params = array()])
array read ( &$Model, [array $query = array()], Model $Model)
void rollback ()
boolean setTimeout (int $ms)
boolean truncate (mixed $table)
boolean update ( &$Model, [array $fields = null], [array $values = null], [ $conditions = null], Model $Model)
boolean updateAll ( &$Model, [array $fields = null], [array $conditions = null], Model $Model)
mixed value (mixed $data, [string $column = null], [boolean $read = true])
void _convertId ( &$mixed, [bool $conditions = false], mixed $mixed)
void _prepareLogQuery ( &$Model, mixed $Model)
void _setEmptyValues ( &$data, [array $integers = array('limit', 'offset')], mixed $data)
array _stringify ([ &$args = array()], [int $level = 0], array $args)
void _stripAlias ([ &$args = array()], [string $alias = 'Model'], [bool $recurse = true], [string $check = 'key'], array $args)
Variables
array $columns = array(
'boolean' => array('name' => 'boolean'),'string'=>array('name'=>'varchar'),'text'=>array('name'=>'text'),'integer'=>array('name'=>'integer','format'=>null,'formatter'=>'intval'),'float'=>array('name'=>'float','format'=>null,'formatter'=>'floatval'),'datetime'=>array('name'=>'datetime','format'=>null,'formatter'=>'MongodbDateFormatter'),'timestamp'=>array('name'=>'timestamp','format'=>null,'formatter'=>'MongodbDateFormatter'),'time'=>array('name'=>'time','format'=>null,'formatter'=>'MongodbDateFormatter'),'date'=>array('name'=>'date','format'=>null,'formatter'=>'MongodbDateFormatter'),)
(line 101)

column definition

  • access: public
boolean $connected = null (line 47)

Are we connected to the DataSource?

true - yes null - haven't tried yet false - nope, and we can't connect

  • access: public
array $_baseConfig = array(
'set_string_id' => true,
'persistent' => true,
'host' => 'localhost',
'database' => '',
'port' => '27017',
'login' => '',
'password' => ''
)
(line 86)

Base Config

set_string_id: true: In read() method, convert MongoId object to string and set it to array 'id'. false: not convert and set.

  • access: public
resource $_db = null (line 55)

Database Instance

  • access: protected
array $_defaultSchema = array(
'_id' => array('type' => 'string', 'length' => 24, 'key' => 'primary'),'created'=>array('type'=>'datetime','default'=>null))
(line 119)

Default schema for the mongo models

  • access: protected
string $_driverVersion = Mongo::VERSION (line 63)

Mongo Driver Version

  • access: protected
mixed $_startTime = null (line 73)

startTime property

If debugging is enabled, stores the (micro)time the current query started

  • var: null
  • access: protected
Methods
Constructor __construct (line 134)

construct method

By default don't try to connect until you need to

  • access: public
void __construct ([array $config = array()], [bool $autoConnect = false])
  • array $config: Configuration array
  • bool $autoConnect: false
Destructor __destruct (line 143)

Destruct

  • access: public
void __destruct ()
begin (line 411)

begin method

Mongo doesn't support transactions

  • access: public
void begin ()
calculate (line 422)

Calculate

  • access: public
array calculate ( &$Model, Model $Model)
  • Model $Model
  • &$Model
close (line 332)

Close database connection

  • return: Connected
  • access: public
boolean close ()
commit (line 157)

commit method

MongoDB doesn't support transactions

  • access: public
void commit ()
connect (line 172)

Connect to the database

If using 1.0.2 or above use the mongodb:// format to connect The connect syntax changed in version 1.0.2 - so check for that too

If authentication information in present then authenticate the connection

  • return: Connected
  • access: public
boolean connect ()
create (line 447)

Create Data

  • return: Insert result
  • access: public
boolean create ( &$Model, [array $fields = null], [array $values = null], Model $Model)
  • Model $Model: Model Instance
  • array $fields: Field data
  • array $values: Save data
  • &$Model
createConnectionName (line 210)

create connection name.

  • access: public
void createConnectionName (array $config, string $version)
  • array $config
  • string $version: version of MongoDriver
createSchema (line 497)

createSchema method

Mongo no care for creating schema. Mongo work with no schema.

  • access: public
void createSchema (mixed $schema, [mixed $tableName = null])
  • mixed $schema
  • mixed $tableName: null
delete (line 851)

Delete Data

For deleteAll(true, false) calls - conditions will arrive here as true - account for that and convert to an empty array For deleteAll(array('some conditions')) calls - conditions will arrive here as: array( Alias._id => array(1, 2, 3, ...) )

This format won't be understood by mongodb, it'll find 0 rows. convert to:

array( Alias._id => array('$in' => array(1, 2, 3, ...)) )

  • return: Update result
  • TODO: bench remove() v drop. if it's faster to drop - just drop the collection taking into account existing indexes (recreate just the indexes)
  • access: public
boolean delete ( &$Model, [array $conditions = null], Model $Model)
  • Model $Model: Model Instance
  • array $conditions
  • &$Model
deriveSchemaFromData (line 804)

deriveSchemaFromData method

  • access: public
void deriveSchemaFromData (mixed $Model, [array $data = array()])
  • mixed $Model
  • array $data: array()
describe (line 386)

Describe

Automatically bind the schemaless behavior if there is no explicit mongo schema. When called, if there is model data it will be used to derive a schema. a row is plucked out of the db and the data obtained used to derive the schema.

  • return: if model instance has mongoSchema, return it.
  • access: public
array describe ( &$Model, [ $field = null], Model $Model)
  • Model $Model
  • &$Model
  • $field
disconnect (line 342)

Disconnect from the database

  • return: Connected
  • access: public
boolean disconnect ()
distinct (line 550)

distinct method

  • access: public
void distinct ( &$Model, [array $keys = array()], [array $params = array()], mixed $Model)
  • mixed $Model
  • array $keys: array()
  • array $params: array()
  • &$Model
dropSchema (line 511)

dropSchema method

Return a command to drop each table

  • access: public
void dropSchema (mixed $schema, [mixed $tableName = null])
  • mixed $schema
  • mixed $tableName: null
ensureIndex (line 635)

ensureIndex method

  • access: public
void ensureIndex ( &$Model, [array $keys = array()], [array $params = array()], mixed $Model)
  • mixed $Model
  • array $keys: array()
  • array $params: array()
  • &$Model
execute (line 1142)

execute method

If there is no query or the query is true, execute has probably been called as part of a db-agnostic process which does not have a mongo equivalent, don't do anything.

  • access: public
void execute (mixed $query, [array $params = array()])
  • mixed $query
  • array $params: array()
getMongoCollection (line 297)

get MongoDB Collection Object

  • return: MongoDB Collection Object
  • access: public
mixed getMongoCollection ( &$Model)
  • &$Model
getMongoDb (line 284)

get MongoDB Object

  • return: MongoDB Object
  • access: public
mixed getMongoDb ()
group (line 596)

group method

  • access: public
void group ( &$Model, [array $params = array()], mixed $Model)
  • mixed $Model
  • array $params:

    array() Set params same as MongoCollection::group() key,initial, reduce, options(conditions, finalize)

    Ex. $params = array( 'key' => array('field' => true), 'initial' => array('csum' => 0), 'reduce' => 'function(obj, prev){prev.csum += 1;}', 'options' => array( 'condition' => array('age' => array('$gt' => 20)), 'finalize' => array(), ), );

  • &$Model
insertMulti (line 238)

Inserts multiple values into a table

  • access: public
void insertMulti (string $table, string $fields, array $values)
  • string $table
  • string $fields
  • array $values
isConnected (line 271)

check connection to the database

  • return: Connected
  • access: public
boolean isConnected ()
isInterfaceSupported (line 319)

isInterfaceSupported method

listSources is infact supported, however: cake expects it to return a complete list of all possible sources in the selected db - the possible list of collections is infinte, so it's faster and simpler to tell cake that the interface is /not/ supported so it assumes that <insert name of your table here> exist

  • access: public
void isInterfaceSupported (mixed $interface)
  • mixed $interface
listSources (line 358)

Get list of available Collections

  • return: Collections
  • access: public
array listSources ([array $data = null])
  • array $data
logQuery (line 1241)

logQuery method

Set timers, errors and refer to the parent If there are arguments passed - inject them into the query Show MongoIds in a copy-and-paste-into-mongo format

  • access: public
void logQuery (mixed $query, [array $args = array()])
  • mixed $query
  • array $args: array()
mapReduce (line 1094)

mapReduce

  • return: false or array
  • access: public
mixed mapReduce (mixed $query, [integer $timeout = null])
  • mixed $query
  • integer $timeout: (milli second)
name (line 434)

Quotes identifiers.

MongoDb does not need identifiers quoted, so this method simply returns the identifier.

  • return: The quoted identifier.
  • access: public
string name (string $name)
  • string $name: The identifier to quote.
query (line 1067)

query method If call getMongoDb() from model, this method call getMongoDb().

  • access: public
void query (mixed $query, [array $params = array()])
  • mixed $query
  • array $params: array()
read (line 908)

Read Data

For deleteAll(true) calls - the conditions will arrive here as true - account for that and switch to an empty array

  • return: Results
  • access: public
array read ( &$Model, [array $query = array()], Model $Model)
  • Model $Model: Model Instance
  • array $query: Query data
  • &$Model
rollback (line 1039)

rollback method

MongoDB doesn't support transactions

  • access: public
void rollback ()
setTimeout (line 1222)

setTimeout Method

Sets the MongoCursor timeout so long queries (like map / reduce) can run at will. Expressed in milliseconds, for an infinite timeout, set to -1

  • access: public
boolean setTimeout (int $ms)
  • int $ms
truncate (line 1050)

Deletes all the records in a table

  • access: public
boolean truncate (mixed $table)
  • mixed $table: A string or model class representing the table to be truncated
update (line 677)

Update Data

This method uses $set operator automatically with MongoCollection::update(). If you don't want to use $set operator, you can chose any one as follw.

  1. Set TRUE in Model::mongoNoSetOperator property.
  2. Set a mongodb operator in a key of save data as follow. Model->save(array('_id' => $id, '$inc' => array('count' => 1))); Don't use Model::mongoSchema property, CakePHP delete '$inc' data in Model::Save().
  3. Set a Mongo operator in Model::mongoNoSetOperator property. Model->mongoNoSetOperator = '$inc'; Model->save(array('_id' => $id, array('count' => 1)));

  • return: Update result
  • access: public
boolean update ( &$Model, [array $fields = null], [array $values = null], [ $conditions = null], Model $Model)
  • Model $Model: Model Instance
  • array $fields: Field data
  • array $values: Save data
  • &$Model
  • $conditions
updateAll (line 768)

Update multiple Record

  • return: Update result
  • access: public
boolean updateAll ( &$Model, [array $fields = null], [array $conditions = null], Model $Model)
  • Model $Model: Model Instance
  • array $fields: Field data
  • array $conditions
  • &$Model
value (line 1123)

Prepares a value, or an array of values for database queries by quoting and escaping them.

  • return: Prepared value or array of values.
  • access: public
mixed value (mixed $data, [string $column = null], [boolean $read = true])
  • mixed $data: A value or an array of values to prepare.
  • string $column: The column into which this data will be inserted
  • boolean $read: Value to be used in READ or WRITE context
_convertId (line 1271)

convertId method

$conditions is used to determine if it should try to auto correct _id => array() queries it only appies to conditions, hence the param name

  • access: protected
void _convertId ( &$mixed, [bool $conditions = false], mixed $mixed)
  • mixed $mixed
  • bool $conditions: false
  • &$mixed
_prepareLogQuery (line 1200)

prepareLogQuery method

Any prep work to log a query

  • access: protected
void _prepareLogQuery ( &$Model, mixed $Model)
  • mixed $Model
  • &$Model
_setEmptyValues (line 1176)

Set empty values, arrays or integers, for the variables Mongo uses

  • access: protected
void _setEmptyValues ( &$data, [array $integers = array('limit', 'offset')], mixed $data)
  • mixed $data
  • array $integers: array('limit', 'offset')
  • &$data
_stringify (line 1299)

stringify method

Takes an array of args as an input and returns an array of json-encoded strings. Takes care of any objects the arrays might be holding (MongoID);

  • access: protected
array _stringify ([ &$args = array()], [int $level = 0], array $args)
  • array $args: array()
  • int $level: 0 internal recursion counter
  • &$args
_stripAlias (line 1339)

Convert automatically array('Model.field' => 'foo') to array('field' => 'foo')

This introduces the limitation that you can't have a (nested) field with the same name as the model But it's a small price to pay to be able to use other behaviors/functionality with mongoDB

  • access: protected
void _stripAlias ([ &$args = array()], [string $alias = 'Model'], [bool $recurse = true], [string $check = 'key'], array $args)
  • array $args: array()
  • string $alias: 'Model'
  • bool $recurse: true
  • string $check: 'key', 'value' or 'both'
  • &$args

Documentation generated on Tue, 26 Jul 2011 01:09:01 +0900 by phpDocumentor 1.4.3