src/DocumentManager.php
private function perfomOperations($insert, $update, $remove)
    {
        $bulkOperations = [];
        foreach ($insert as $id => $document) {
            $repository = $this->getObjectRepository($document);
            if ($repository instanceof GridFSRepository) {
                $repository->insertOne($document);
                unset($insert[$id]);
            } else {
                $query = $repository->insertOne($document, ['getQuery' => true]);
                $repositoryId = spl_object_hash($repository);
                $bulkOperations[$repositoryId] = isset($bulkOperations[$repositoryId]) ? $bulkOperations[$repositoryId] : $repository->createBulkWriteQuery();
                $bulkOperations[$repositoryId]->addQuery($query);
            }
        }

        foreach ($update as $id => $document) {
            $repository = $this->getObjectRepository($document);
            $query = $repository->updateOne($document, [], ['getQuery' => true]);
            $repositoryId = spl_object_hash($repository);
            $bulkOperations[$repositoryId] = isset($bulkOperations[$repositoryId]) ? $bulkOperations[$repositoryId] : $repository->createBulkWriteQuery();
            $bulkOperations[$repositoryId]->addQuery($query);
        }

        foreach ($remove as $id => $document) {
            $repository = $this->getObjectRepository($document);
            if ($repository instanceof GridFSRepository) {
                $repository->deleteOne($document);
                unset($remove[$id]);
            } else {
                $query = $repository->deleteOne($document, ['getQuery' => true]);
                $repositoryId = spl_object_hash($repository);
                $bulkOperations[$repositoryId] = $bulkOperations[$repositoryId] ?? $repository->createBulkWriteQuery();
                $bulkOperations[$repositoryId]->addQuery($query);
            }
        }

        foreach (array_merge($insert, $update, $remove) as $id => $document) {
            $repository = $this->getObjectRepository($document);
            $repository->getClassMetadata()->getEventManager()->execute(EventManager::EVENT_PRE_FLUSH, $document);
        }

        foreach ($bulkOperations as $bulkOperation) {
            $bulkOperation->execute();
        }

        foreach (array_merge($insert, $update) as $id => $document) {
            $repository = $this->getObjectRepository($document);
            $repository->getClassMetadata()->getEventManager()->execute(EventManager::EVENT_POST_FLUSH, $document);
            $repository->cacheObject($document);
        }

        $this->flush();
    }
private function perfomOperations($insert, $update, $remove)
    {
        $bulkOperations = [];
        foreach ($insert as $id => $document) {
            $repository = $this->getObjectRepository($document);
            if ($repository instanceof GridFSRepository) {
                $repository->insertOne($document);
                unset($insert[$id]);
            } else {
                $query = $repository->insertOne($document, ['getQuery' => true]);
                $repositoryId = spl_object_hash($repository);
                $bulkOperations[$repositoryId] = isset($bulkOperations[$repositoryId]) ? $bulkOperations[$repositoryId] : $repository->createBulkWriteQuery();
                $bulkOperations[$repositoryId]->addQuery($query);
            }
        }

        foreach ($update as $id => $document) {
            $repository = $this->getObjectRepository($document);
            $query = $repository->updateOne($document, [], ['getQuery' => true]);
            $repositoryId = spl_object_hash($repository);
            $bulkOperations[$repositoryId] = isset($bulkOperations[$repositoryId]) ? $bulkOperations[$repositoryId] : $repository->createBulkWriteQuery();
            $bulkOperations[$repositoryId]->addQuery($query);
        }

        foreach ($remove as $id => $document) {
            $repository = $this->getObjectRepository($document);
            if ($repository instanceof GridFSRepository) {
                $repository->deleteOne($document);
                unset($remove[$id]);
            } else {
                $query = $repository->deleteOne($document, ['getQuery' => true]);
                $repositoryId = spl_object_hash($repository);
                $bulkOperations[$repositoryId] = $bulkOperations[$repositoryId] ?? $repository->createBulkWriteQuery();
                $bulkOperations[$repositoryId]->addQuery($query);
            }
        }

        foreach (array_merge($insert, $update, $remove) as $id => $document) {
            $repository = $this->getObjectRepository($document);
            $repository->getClassMetadata()->getEventManager()->execute(EventManager::EVENT_PRE_FLUSH, $document);
        }

        foreach ($bulkOperations as $bulkOperation) {
            $bulkOperation->execute();
        }

        foreach (array_merge($insert, $update) as $id => $document) {
            $repository = $this->getObjectRepository($document);
            $repository->getClassMetadata()->getEventManager()->execute(EventManager::EVENT_POST_FLUSH, $document);
            $repository->cacheObject($document);
        }

        $this->flush();
    }
private function perfomOperations ( $ insert , $ update , $ remove ) { $ bulkOperations = [ ] ; foreach ( $ insert as $ id => $ document ) { $ repository = $ this -> getObjectRepository ( $ document ) ; if ( $ repository instanceof GridFSRepository ) { $ repository -> insertOne ( $ document ) ; unset ( $ insert [ $ id ] ) ; } else { $ query = $ repository -> insertOne ( $ document , [ 'getQuery' => true ] ) ; $ repositoryId = spl_object_hash ( $ repository ) ; $ bulkOperations [ $ repositoryId ] = isset ( $ bulkOperations [ $ repositoryId ] ) ? $ bulkOperations [ $ repositoryId ] : $ repository -> createBulkWriteQuery ( ) ; $ bulkOperations [ $ repositoryId ] -> addQuery ( $ query ) ; } } foreach ( $ update as $ id => $ document ) { $ repository = $ this -> getObjectRepository ( $ document ) ; $ query = $ repository -> updateOne ( $ document , [ ] , [ 'getQuery' => true ] ) ; $ repositoryId = spl_object_hash ( $ repository ) ; $ bulkOperations [ $ repositoryId ] = isset ( $ bulkOperations [ $ repositoryId ] ) ? $ bulkOperations [ $ repositoryId ] : $ repository -> createBulkWriteQuery ( ) ; $ bulkOperations [ $ repositoryId ] -> addQuery ( $ query ) ; } foreach ( $ remove as $ id => $ document ) { $ repository = $ this -> getObjectRepository ( $ document ) ; if ( $ repository instanceof GridFSRepository ) { $ repository -> deleteOne ( $ document ) ; unset ( $ remove [ $ id ] ) ; } else { $ query = $ repository -> deleteOne ( $ document , [ 'getQuery' => true ] ) ; $ repositoryId = spl_object_hash ( $ repository ) ; $ bulkOperations [ $ repositoryId ] = $ bulkOperations [ $ repositoryId ] ?? $ repository -> createBulkWriteQuery ( ) ; $ bulkOperations [ $ repositoryId ] -> addQuery ( $ query ) ; } } foreach ( array_merge ( $ insert , $ update , $ remove ) as $ id => $ document ) { $ repository = $ this -> getObjectRepository ( $ document ) ; $ repository -> getClassMetadata ( ) -> getEventManager ( ) -> execute ( EventManager :: EVENT_PRE_FLUSH , $ document ) ; } foreach ( $ bulkOperations as $ bulkOperation ) { $ bulkOperation -> execute ( ) ; } foreach ( array_merge ( $ insert , $ update ) as $ id => $ document ) { $ repository = $ this -> getObjectRepository ( $ document ) ; $ repository -> getClassMetadata ( ) -> getEventManager ( ) -> execute ( EventManager :: EVENT_POST_FLUSH , $ document ) ; $ repository -> cacheObject ( $ document ) ; } $ this -> flush ( ) ; }
Perfom operation on collections

@param   array   $insert     Objects to insert
@param   array   $update     Objects to update
@param   array   $remove     Objects to remove
@return  void
Perfom operation on collections