Webiny\Component\Mongo\Mongo::update PHP Method

update() public method

public update ( $collectionName, $filter, $update, array $options = [] )
$options array
    public function update($collectionName, $filter, $update, array $options = [])
    {
        return $this->bridge->update($this->cName($collectionName), $filter, $update, $options);
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * Save all the entries from the buffer.
  */
 public function save()
 {
     $entries = $this->logBuffer->getEntries();
     $entrySkeleton = ['ts' => $this->ts, 'month' => $this->month, 'year' => $this->year];
     $dimensionSkeleton = ['ts' => $this->ts, 'month' => $this->month, 'year' => $this->year];
     /**
      * @var $e LogEntry
      */
     foreach ($entries as $e) {
         // build entry
         $entry = $entrySkeleton;
         $entry['entity'] = $e->getName();
         $entry['ref'] = $e->getRef();
         // insert or update the DAILY stat
         $this->mongo->update(self::ADB_STATS_DAILY, ['entity' => $e->getName(), 'ref' => $e->getRef(), 'ts' => $this->ts], ['$inc' => ['count' => $e->getIncrement()], '$setOnInsert' => $entry], ['upsert' => true]);
         // insert or update the MONTHLY stat
         unset($entry['ts']);
         $entry['month'] = $this->month;
         $entry['year'] = $this->year;
         $this->mongo->update(self::ADB_STATS_MONTHLY, ['entity' => $e->getName(), 'ref' => $e->getRef(), 'ts' => $this->monthTs], ['$inc' => ['count' => $e->getIncrement()], '$setOnInsert' => $entry], ['upsert' => true]);
         // insert dimensions for the entry
         $dimEntry = $dimensionSkeleton;
         $dimEntry['entity'] = $e->getName();
         /**
          * @var $dim LogDimension
          */
         foreach ($e->getDimensions() as $dim) {
             $dimEntry['name'] = $dim->getName();
             $dimEntry['value'] = $dim->getValue();
             $this->mongo->update(self::ADB_DIMS, ['name' => $dim->getName(), 'value' => $dim->getValue(), 'entity' => $e->getName(), 'ts' => $this->ts], ['$inc' => ['count.' . $e->getRef() => $dim->getIncrement(), 'total' => $dim->getIncrement()], '$setOnInsert' => $dimEntry], ['upsert' => true]);
         }
     }
     // clear buffer
     $this->logBuffer = new LogBuffer();
 }
All Usage Examples Of Webiny\Component\Mongo\Mongo::update