original_string: public function persist($collection, array $document)
      {
          
  
          if ($collection instanceof Collection) {
              $collectionName = $collection->getName();
          } else {
              $collectionName = $collection;
              $collection = static::factory($collection);
          }
          
          $data = $this->marshall($document);
          $result = false;
  
          
          if (!isset($document['$id'])) {
              $id = $this->insert($collectionName, $data);
              if ($id) {
                  $data['$id'] = $id;
                  $result = $data;
              }
          } else {
              $data['id'] = $document['$id'];
              unset($data['$id']);
              $result = $this->update($collectionName, $data);
  
              if ($result) {
                  $result = $data;
              }
          }
  
          return $this->unmarshall($result);
      }
code: public function persist($collection, array $document)
      {
          
  
          if ($collection instanceof Collection) {
              $collectionName = $collection->getName();
          } else {
              $collectionName = $collection;
              $collection = static::factory($collection);
          }
          
          $data = $this->marshall($document);
          $result = false;
  
          
          if (!isset($document['$id'])) {
              $id = $this->insert($collectionName, $data);
              if ($id) {
                  $data['$id'] = $id;
                  $result = $data;
              }
          } else {
              $data['id'] = $document['$id'];
              unset($data['$id']);
              $result = $this->update($collectionName, $data);
  
              if ($result) {
                  $result = $data;
              }
          }
  
          return $this->unmarshall($result);
      }
code_tokens: public function persist ( $ collection , array $ document ) { if ( $ collection instanceof Collection ) { $ collectionName = $ collection -> getName ( ) ; } else { $ collectionName = $ collection ; $ collection = static :: factory ( $ collection ) ; } $ data = $ this -> marshall ( $ document ) ; $ result = false ; if ( ! isset ( $ document [ '$id' ] ) ) { $ id = $ this -> insert ( $ collectionName , $ data ) ; if ( $ id ) { $ data [ '$id' ] = $ id ; $ result = $ data ; } } else { $ data [ 'id' ] = $ document [ '$id' ] ; unset ( $ data [ '$id' ] ) ; $ result = $ this -> update ( $ collectionName , $ data ) ; if ( $ result ) { $ result = $ data ; } } return $ this -> unmarshall ( $ result ) ; }
docstring: Sync data to database. If it's new data, we insert it as new document, otherwise, if the document exists, we just update it.
  
  @param Collection $collection
  @param Model $model
  
  @return bool
docstring_tokens: Sync data to database . If it s new data we insert it as new document otherwise if the document exists we just update it .