Inserts new elements for a PersistentCollection instances.

This method is intended to be used with the "pushAll" and "addToSet" strategies.

@param PersistentCollectionInterface[] $collections
@param array                           $options
763499
private function insertElements(object $parent, array $collections, array $options) : void
    {
        $pushAllPathCollMap  = [];
        $addToSetPathCollMap = [];
        $pushAllPaths        = [];
        $addToSetPaths       = [];
        $diffsMap            = [];

        foreach ($collections as $coll) {
            $coll->initialize();
            if (! $this->uow->isCollectionScheduledForUpdate($coll)) {
                continue;
            }
            $insertDiff = $coll->getInsertDiff();

            if (empty($insertDiff)) {
                continue;
            }

            $mapping  = $coll->getMapping();
            $strategy = $mapping['strategy'];

            [$propertyPath ]         = $this->getPathAndParent($coll);
            $diffsMap[$propertyPath] = $insertDiff;

            switch ($strategy) {
                case ClassMetadata::STORAGE_STRATEGY_PUSH_ALL:
                    $pushAllPathCollMap[$propertyPath] = $coll;
                    $pushAllPaths[]                    = $propertyPath;
                    break;

                case ClassMetadata::STORAGE_STRATEGY_ADD_TO_SET:
                    $addToSetPathCollMap[$propertyPath] = $coll;
                    $addToSetPaths[]                    = $propertyPath;
                    break;

                default:
                    throw new LogicException('Invalid strategy ' . $strategy . ' given for insertCollections');
            }
        }

        if (! empty($pushAllPaths)) {
            $this->pushAllCollections(
                $parent,
                $pushAllPaths,
                $pushAllPathCollMap,
                $diffsMap,
                $options
            );
        }
        if (empty($addToSetPaths)) {
            return;
        }

        $this->addToSetCollections(
            $parent,
            $addToSetPaths,
            $addToSetPathCollMap,
            $diffsMap,
            $options
        );
    }
374137
private function loadReferenceManyWithRepositoryMethod(PersistentCollectionInterface $collection)
    {
        $iterator  = $this->createReferenceManyWithRepositoryMethodIterator($collection);
        $mapping   = $collection->getMapping();
        $documents = $iterator->toArray();
        foreach ($documents as $key => $obj) {
            if ($mapping->type === Type::MAP) {
                $collection->set($key, $obj);
            } else {
                $collection->add($obj);
            }
        }
    }
226958
protected function removeCollection(Collection $collection, array $options = []) {
		$ids = $collection->_id;
		
		if (count($ids) !== $collection->count()) {
			throw new Exceptions\OperationError('Some of the models has no ID');
		}
		
		$ids = array_map([$this, 'normalizeId'], $ids);
		
		return $this->getAdapter()->remove(
			$this->getTableName(),
			['_id' => [
				'$in' => $ids
			]],
			$options
		);
	}
461105
public function addCollection(self $collection)
    {
        $this->renderDefinitions = \array_merge($this->renderDefinitions, $collection->all());
        $this->resources = \array_merge($this->resources, $collection->getResources());
    }
175140
public function createCollection($collectionName, array $options = [])
    {
        $this->document = $this->db->getQueryBuilder()->createCollection($collectionName, $options);

        $result = current($this->execute()->toArray());
        return $result['ok'] > 0;
    }
14457
private function loadEmbedManyCollection(PersistentCollectionInterface $collection)
    {
        $rawData = $collection->getRawData();

        if ($rawData) {
            $mapping = $collection->getMapping();
            $owner   = $collection->getOwner();

            foreach ($rawData as $key => $data) {
                if ($mapping->type === Type::MAP) {
                    $key = (string)$key;
                } else {
                    $key = (int)$key;
                }

                $embeddedDocument = $this->uow->getAssociationPersister()->loadEmbed($mapping, $data, $owner, $key, $collection->isReadOnly());

                if ($mapping->type === Type::MAP) {
                    $collection->set($key, $embeddedDocument);
                } else {
                    $collection->add($embeddedDocument);
                }
            }
        }
    }
1203844
public function merge(AbstractCollection $collection)
    {
        if (is_subclass_of($collection, get_class($this)) === true || get_class($collection) === get_class($this)) {
            $newData = array_merge($this->dataPlaceHolder, $collection->getDataPlaceHolder());
            $this->dataPlaceHolder = $newData;
        } else {
            $msg = "Only collections with compliant types can be merged ";
            $msg.= "('" . get_class($this) . "' vs '" . get_class($collection) . "').";
            throw new InvalidArgumentException($msg);
        }
    }
891717
public function addAll(array $elements)
    {
        if (is_array($elements)) {
            foreach ($elements as $element) {
                $this->_items[] = $element;
            }
            $this->_iterator = null;
        } else {
            throw new CollectionException('Given array can not added to collection, because it is no array.', E_NOTICE);
        }
    }
369835
public function createCollection($collectionName, array $options = [])
    {
        $cursor = $this->executeCommand(['create' => $collectionName], $options);

        return $cursor->current();
    }
192156
private function setCollection(PersistentCollectionInterface $coll)
    {
        list($qb, $path, $parent) = $this->getQueryPathAndParent($coll);

        $coll->initialize();

        $path->set($coll);
        $this->executeQuery($qb, $parent);
    }
778985
final public function persistMany(array $collection, array $fillable = array())
    {
        foreach ($collection as $item) {
            $this->persist($item, $fillable);
        }

        return true;
    }
1240690
public function listCollections(array $options = [])
    {
        $collections = [];
        foreach ($this->collections as $name => $collection) {
            $collections[] = [
                'name' => $this->name . '.' . $name,
                'options' => $collection['options']
            ];
        }

        return new CollectionInfoLegacyIterator(new ArrayIterator($collections));
    }
1347327
private function loadReferenceManyCollectionInverseSide(PersistentCollectionInterface $collection)
    {
        $query     = $this->createReferenceInverseSideQuery($collection->getMapping(), $collection->getOwner());
        $documents = $query->execute()->toArray();

        foreach ($documents as $key => $document) {
            $collection->add($document);
        }
    }
752825
public function loadCollection(PersistentCollectionInterface $collection) : void
    {
        if ($collection->getOwner() === null) {
            throw PersistentCollectionException::ownerRequiredToLoadCollection();
        }

        $this->getDocumentPersister(get_class($collection->getOwner()))->loadCollection($collection);
        $this->lifecycleEventManager->postCollectionLoad($collection);
    }
290038
public function addManyToManyCollections($collections)
    {
        if (!is_array($collections)) {
            $collections = [$collections];
        }
        $this->manyToManyCollections = array_merge($this->manyToManyCollections, $collections);

        return $this;
    }
130624
public function insert(array $data, $options = [])
    {
        $maxRetries = $this->maxRetries;
        $tries = 0;

        // Check whether we're dealing with a batch insert.
        if (isset($data[0]) && is_array($data[0])) {
            // Insert using batchInsert
            do {
                try {
                    $result = $this->collection->batchInsert($data, $options);
                    break;
                } catch (MongoCursorException $e) {
                    // Retry "save" in case of rediscovery latency issues
                    // in replica set failover. Error codes 10107, 13435, and 10058
                    // are MongoCursorException's "not master" errors.
                    if (in_array($e->getCode(), [10107, 13435, 10058])) {
                        if ($tries === $maxRetries) {
                            throw $e;
                        } else {
                            $tries++;
                            continue;
                        }
                    } else {
                        throw $e;
                    }
                }
            } while ($tries <= $maxRetries);

            if (! $result || ! ($result === true || (bool) $result['ok'])) {
                return false;
            }

            $result = [];

            foreach ($data as $r) {
                // Collect all the id's for the return value
                $result[] = $r['_id'];
            }

            // Return all inserted id's.
            return $result;
        }

        do {
            try {
                $result = $this->collection->insert($data, $options);
                break;
            } catch (MongoCursorException $e) {
                // Retry "save" in case of rediscovery latency issues
                // in replica set failover. Error codes 10107, 13435, and 10058
                // are MongoCursorException's "not master" errors.
                if (in_array($e->getCode(), [10107, 13435, 10058])) {
                    if ($tries === $maxRetries) {
                        throw $e;
                    } else {
                        $tries++;
                        continue;
                    }
                } else {
                    throw $e;
                }
            }
        } while ($tries <= $maxRetries);

        if ($result === true || (bool) $result['ok']) {
            return $data['_id'];
        }

        return false;
    }
887970
public function add(iterable $elements): CollectionInterface
    {
        foreach ($elements as $key => $element) {
            $this->set($key, $element);
        }

        return $this;
    }