Ajoute un nouveau document à une collection

@param  type     $collection
@param  type     $data
@return boolean
@throws \Exception
332035
public static function add($collection, $data)
  {
    static::checkConnexion();
    $collection = self::$db->$collection;
    if (is_string($data)) {
      $data = json_decode($data, true);
      if(!$data){
        throw new \Exception('Requête JSON formulée incorrectement');
      }
    }
    $r = $collection->insert($data);
    if ($r['ok']) {
      return true;
    } else {
      return false;
    }
  }
1085833
public function create($data)
    {
        $descriptor = new VarDescriptor($data->getName());
        $descriptor->setDescription($data->getDescription());
        $descriptor->setVariableName($data->getVariableName());

        $types = $this->builder->buildDescriptor(
            new Collection($data->getVariableName() == '$this' ? array('$this') : $data->getTypes())
        );
        $descriptor->setTypes($types);

        return $descriptor;
    }
565590
public function get($collection)
    {
        $collection = $this->makeCollection($collection);

        $url      = UrlHelper::buildUrl(Urls::URL_COLLECTION, [$collection]);
        $response = $this->getConnection()->get($url);

        $data = $response->getJson();

        return Collection::createFromArray($data);
    }
667330
public function createDocument($collection, array $data, array $options = [])
    {
        $this->setOptions($options);
        $doc = new Document($this->client, $this->database, $collection);
        $doc->setHeaders($this->getHeaders());
        $rs = $doc->create($data);
        $this->checkResponse($rs);
        unset($rs['_curl_info']);

        return $rs;
    }
580587
protected function mapRequestDataToElementCollection($data, ElementCollection $children)
    {
        $children->forAll(function (ElementInterface $element) use ($data) {
            $propertyPath = $this->getPropertyPathAsIndex($element);
            if (array_key_exists($element->getName(), $data)) {
                $values = $this->propertyAccessor->getValue($data, $propertyPath);
                $this->mapRequestDataToElement($values, $element);
            }
        });
    }
1094535
public function create($data)
    {
        $descriptor = new ThrowsDescriptor($data->getName());
        $descriptor->setDescription($data->getDescription());
        $descriptor->setTypes(
            $this->builder->buildDescriptor(new Collection($data->getTypes()))
        );

        return $descriptor;
    }
553172
public function update($collection = '', $data = array(), $options = array(), $literal = false)
		{
			if (empty($collection)) {
				throw new Exception("No Mongo collection selected to update");
			}

			if (empty($data) or ! Arrays::is($data)) {
				throw new Exception("Nothing to update in Mongo collection or update value is not an array");
			}

			try {
				$options = array_merge($options, array('fsync' => true, 'multiple' => false));

				$this->db->{$collection}->update($this->wheres, (($literal) ? $data : array('$set' => $data)), $options);

				$this->_clear();

				return true;
			} catch (\MongoCursorException $e) {
				throw new Exception("Update of data into MongoDB failed: {$e->getMessage()}", $e->getCode());
			}
		}
495194
public function onPreHandleRequestWithCollection(Collection $collection) {
        $output = new ArrayCollection();
        foreach ($collection as $current) {
            $output->add($current);
        }
        return $output;
    }
39800
function fetchCollectionAttributeHTTPInput( $collection, $collectionAttribute, $http, $base, $contentObjectAttribute )
    {
        if ( $http->hasPostVariable( $base . "_data_text_" . $contentObjectAttribute->attribute( "id" ) ) )
        {
            $dataText = $http->postVariable( $base . "_data_text_" . $contentObjectAttribute->attribute( "id" ) );
            $collectionAttribute->setAttribute( 'data_text', $dataText );
            return true;
        }
        return false;
    }
555720
public function setCollection($collection)
    {
        if (!$this->loaded) {
            $this->load();
        }

        $this->collectionInfo->setCollection($collection);
        return $this;
    }
321048
public function create(array $data = [])
    {
        $collection = parent::create($data);

        if ($this->getCurrentCategory() && $this->getCurrentCategory()->getLevel() >= 2) {
            $collection->addAttributeToFilter('entity_id', ['neq' => (int) $this->getCurrentCategory()->getId()]);

            $rootPath      = array_slice($this->getCurrentCategory()->getPathIds(), 0, 2);
            $pathCondition = implode('/', $rootPath) . '%';
            $collection->addFieldToFilter('path', ['like' => $pathCondition]);
        }

        return $collection;
    }
804567
public static function collectionToModel($collection) {
		if (is_string($collection)) {
			return \Factory::model($collection);
		} else if (!empty($collection['model'])) {
			return new \Object\Collection(['data' => $collection, 'skip_acl' => $collection['skip_acl'] ?? false]);
		} else {
			return null;
		}
	}
801851
public function onPostHandleRequestWithCollection(Collection $oldCollection, Collection $newCollection) {
        $deleted = 0;
        foreach ($oldCollection as $current) {
            if (true === $newCollection->contains($current)) {
                continue;
            }
            $this->getObjectManager()->remove($current);
            ++$deleted;
        }
        return $deleted;
    }
478196
public function update($collection = '', $data = array(), $options = array(), $literal = false)
	{
		if (empty($collection))
		{
			throw new \Mongo_DbException("No Mongo collection selected to update");
		}

		if (empty($data) or ! is_array($data))
		{
			throw new \Mongo_DbException("Nothing to update in Mongo collection or update value is not an array");
		}

		try
		{
			$options = array_merge($options, array('fsync' => true, 'multiple' => false));

			if ($this->profiling)
			{
				$query = json_encode(array(
				'type'			=> 'update',
				'collection'	=> $collection,
				'where'			=> $this->wheres,
				'payload'		=> $data,
				'options'		=> $options,
				));

				$benchmark = \Profiler::start((string) $this->db, $query);
			}

			$this->db->{$collection}->update($this->wheres, (($literal) ? $data : array('$set' => $data)), $options);

			if (isset($benchmark))
			{
				\Profiler::stop($benchmark);
			}

			$this->_clear();
			return true;
		}
		catch (\MongoCursorException $e)
		{
			throw new \Mongo_DbException("Update of data into MongoDB failed: {$e->getMessage()}", $e->getCode());
		}
	}
1035194
public function createFromCollection(Collection $collection)
    {
        $this->operator = new CollectionOperator($collection, $this->request);
        $this->prepare();

        return $this;
    }
883544
public function execute($data) {

        try {
            $config = $this->sanitizeConfig($data);
            $this->isConciliate($config);
            if (! $this->doCancel($config))
                throw new \Exception('impossible to cancel.');

            $this->doUpdates($config);
            return true;
        } catch (\Exception $exception) {
            throw $exception;
        }
    }
690521
private function insertResponseCollectionIntoData(Response $response, $collectionName, array &$data)
    {
        $property = 'cache' . ucfirst($collectionName);
        if ($this->{$property} === false) {
            return;
        }

        $collection = $response->{$collectionName};
        $all = is_array($collection) ? $collection : $collection->toArray();
        if (is_array($this->{$property})) {
            $filtered = [];
            foreach ($this->{$property} as $name) {
                if ($collectionName === 'headers') {
                    $name = strtolower($name);
                }
                if (isset($all[$name])) {
                    $filtered[$name] = $all[$name];
                }
            }
            $all = $filtered;
        }
        $data[$collectionName] = $all;
    }