public function insert(PersistentAbstract $object) { $this->getCache()->clean(array('list')); $data = $object->exportData(); if (!empty($data)) { if ($this->_timestamps) { $data['created'] = $data['modified'] = time(); } // HACK: Mongo driver will modify the $object->_data event if not passed as reference $data = array_merge($data, array()); $data = $this->_mapModelToMongoModel($data); try { $newData = $this->getCollection()->findAndModify(array('servicePackId' => array('$exists' => false)), array('$set' => $data)); } catch (\Exception $e) { throw new MongoException($e->getMessage()); } if (empty($newData)) { throw new MongoException("No more resId available."); } $object->setId($newData['_id']); $object->setResId($newData['resId']); return $object->id; } throw new InvalidArgumentException(get_class($this) . ': Object ID not defined.'); }