/**
  * Note that we use TTL Collections to have the Mongo deamon automatically clean
  * expired entries.
  *
  * @link http://docs.mongodb.org/manual/tutorial/expire-data/
  * @param array $options
  */
 public function __construct(array $options = array())
 {
     if (!extension_loaded('mongo')) {
         Zend_Cache::throwException('The MongoDB extension must be loaded for using this backend !');
     }
     parent::__construct($options);
     // Merge the options passed in; overriding any default options
     $this->_options = array_merge($this->_options, $options);
     $conn = new \MongoClient($this->_getServerConnectionUrl());
     $this->_database = $conn->{$this->_options['dbname']};
     $this->_collection = $this->_database->selectCollection($this->_options['collection']);
     $this->_collection->createIndex(array('tags' => 1), array('background' => true));
     $this->_collection->createIndex(array('expires_at' => 1), array('background' => true, 'expireAfterSeconds' => 0));
 }
Exemple #2
0
 public function __construct(MongoBaseDatabase $database, $database_name, $collection_name)
 {
     $this->database = $database;
     $this->name = $collection_name;
     $mongo_db = $database->getMasterConnection()->selectDB($database_name);
     $collection_names = $mongo_db->getCollectionNames();
     if (!in_array($collection_name, $collection_names)) {
         // create
         $this->masterCollection = $mongo_db->createCollection($collection_name);
     } else {
         $this->masterCollection = $mongo_db->selectCollection($collection_name);
     }
     $this->masterMongoDb = $mongo_db;
     // slave
     $this->slaveMongoDb = $database->getSlaveConnection()->selectDB($database_name);
     $this->slaveCollection = $this->slaveMongoDb->selectCollection($collection_name);
 }
 /**
  * getCollection get a handle to the collection object
  *
  * @access private
  * @return MongoCollection the mongo collection class reffering to the
  *                         appropriate dataset
  */
 private function getCollection()
 {
     // if the collection is not already cached
     if (empty($this->collection)) {
         // selects the collection if it exists
         $this->collection = $this->db->selectCollection(self::COLLECTION);
         // or creates a new one if it doesn't
         if (empty($this->collection)) {
             $this->collection = $this->db->createCollection(self::COLLECTION);
         }
     }
     return $this->collection;
 }
Exemple #4
0
 /**
  * Create Schema
  *
  * @return DBAL
  */
 public function createSchema()
 {
     $this->connection->selectCollection($this->tableName)->ensureIndex('version', array('unique' => 1));
     return $this;
 }