PHP Classes

File: doc/

Recommend this page to a friend!
  Classes of Xavier Pérez   XMongoDB   doc/   Download  
File: doc/
Role: Auxiliary data
Content type: text/markdown
Description: Auxiliary data
Class: XMongoDB
Build and execute queries to a MongoDB database
Author: By
Last change: Corrections, set
Date: 8 years ago
Size: 2,496 bytes


Class file image Download

Basic Insert / Update / Delete Operations

Insert Options

Insert one document

If you are inserting only one document:

    array('field1' => 'value1',
          'field2' => 'value2',
          'field3' => 'value3'


Insert multiple documents

If you are inserting a group of documents:

$xmongodb->insert_batch('collection', array(
    0 => array('field1' => 'value11','field2' => 'value21','field3' => 'value31'), 
    1 => array('field1' => 'value12','field2' => 'value22','field3' => 'value32')


Update Options

Update a single document

Before an update, you must to specify a where condition:

        array('field2' => 'value2',
              'field3' => 'value3'

This method only will update first collection found in the where condition. Specify an unique key to be sure you update the correct document.

- $options:

* array('upsert' => true)     Create a new document if nothing found

References :

Update multiple documents

        array('field2' => 'value2',
              'field3' => 'value3'

References :

Update using SET

$xmongodb->set(array('field2' => 'value2', 'field3' => 'value3'))


Delete Options

Delete a single document


Delete multiple documents



Reconnect to another mongoDB instance

After you have created the config class, you can reuse to another connection:

// $congig is an object of a previous XMonfoDBConfig instance
$xmongodb_other = new XMongoDB($config);