Example #1
0
 /**
  * Data retreival
  */
 public function sort(array $fields = array())
 {
     $fields_query = new Query($fields, $this->collection);
     $fields_query->compress();
     $this->native->sort($fields_query->compressed);
     return $this;
 }
Example #2
0
 public function findAndModify(array $new_object, array $fields = null, array $options = array())
 {
     $this->compress();
     $uses_modifiers = false;
     // Apply rules to each modifier
     foreach ($new_object as $key => $value) {
         if (strpos($key, '$') === 0) {
             $uses_modifiers = true;
             $set_document = new Query($value, $this->collection);
             $set_document->compress();
             $new_object[$key] = $set_document->compressed;
         }
     }
     // Update Fields
     if ($fields !== null) {
         $fields_object = new Document($fields, $this->collection);
         $fields_object->compress();
         $fields = $fields_object->compressed;
     }
     // Modify Sorting Options
     if ($options && isset($options['sort'])) {
         $sort_object = new Document($options['sort'], $this->collection);
         $sort_object->compress();
         $options['sort'] = $sort_object->compressed;
     }
     // Apple full document replacement compression if no modifiers are used
     if ($uses_modifiers === true) {
         $document = $this->collection->native->findAndModify($this->compressed, $new_object, $fields, $options);
     } else {
         $new_object_document = new Document($new_object, $this->collection);
         $new_object_document->compress();
         $document = $this->collection->native->findAndModify($this->compressed, $new_object_document->compressed, $fields, $options);
     }
     // Decompress returned document
     $document_object = new Document($document, $this->collection);
     $document_object->state = 'compressed';
     $document_object->decompress();
     return $document_object->data;
 }
Example #3
0
 /**
  * Delete Index
  */
 public function deleteIndex($keys)
 {
     if (is_string($keys)) {
         $keys = array($keys => 1);
     }
     $query = new Query($keys, $this);
     $query->compress();
     $query->asDotSyntax();
     return $this->native->deleteIndex($query->compressed);
 }