Esempio n. 1
0
 public function insert($query, $force = false)
 {
     $this->items[] = $query;
     $this->itemsCount++;
     if ($this->itemsCount > 1000 or $force) {
         $result = $this->collection->insertMany($this->items);
         $this->itemsCount = 0;
         $this->items = [];
         return $result;
     }
 }
Esempio n. 2
0
 /**
  * Insert a new record into the database.
  *
  * @param  array  $values
  * @return bool
  */
 public function insert(array $values)
 {
     // Since every insert gets treated like a batch insert, we will have to detect
     // if the user is inserting a single document or an array of documents.
     $batch = true;
     foreach ($values as $value) {
         // As soon as we find a value that is not an array we assume the user is
         // inserting a single document.
         if (!is_array($value)) {
             $batch = false;
             break;
         }
     }
     if (!$batch) {
         $values = [$values];
     }
     // Batch insert
     $result = $this->collection->insertMany($values);
     return 1 == (int) $result->isAcknowledged();
 }