Creates a new raw data for the given source.

@param int    $sourceId
@param string $collectionName
@param array  $data

@return array Response
346563
public function createNew(
        int $sourceId,
        string $collectionName,
        array $data
    ) : array {
        return $this->sendPost(
            sprintf('/profiles/%s/raw', $this->userName),
            [],
            [
                'source_id'  => $sourceId,
                'collection' => $collectionName,
                'data'       => $data
            ]
        );
    }
79449
public function haveInCollection($collection, array $data)
    {
        $collection = $this->driver->getDbh()->selectCollection($collection);
        if ($this->driver->isLegacy()) {
            $collection->insert($data);
            return $data['_id'];
        }

        $response = $collection->insertOne($data);
        return (string) $response->getInsertedId();
    }
962503
public function selectCollection($collectionName, array $options = [])
    {
        $options += [
            'readConcern' => $this->readConcern,
            'readPreference' => $this->readPreference,
            'writeConcern' => $this->writeConcern,
        ];

        return new Collection($this->manager, $this->databaseName, $collectionName, $options);
    }
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;
    }
932552
public function insert($collectionName, array $data, array $options = []) {
		$collection = $this->getCollection($collectionName);
		
		if ($this->_profilerEnabled) {
			$message = 'db.' . $collectionName . '.insert(' . json_encode($data) . ');';
			$event   = $this->getProfiler()->startInsert($message);
		}

		$result  = $collection->insert($data, $options);
		$success = (bool) $result['ok'];
		
		if ($this->_profilerEnabled) {
			$success
				? $event->stopSuccess()
				: $event->stopError();
		}
		
		return $success;
	}
978457
protected function setDataToCollection(Collection $collection, $data)
    {
        // set parent
        if (!empty($data['parent'])) {
            $collectionEntity = $this->collectionRepository->findCollectionById($data['parent']);
            $collection->setParent($this->getApiEntity($collectionEntity, $data['locale']));
        }

        // set other data
        foreach ($data as $attribute => $value) {
            if ($value) {
                switch ($attribute) {
                    case 'title':
                        $collection->setTitle($value);
                        break;
                    case 'key':
                        $collection->setKey($value);
                        break;
                    case 'description':
                        $collection->setDescription($value);
                        break;
                    case 'style':
                        $collection->setStyle($value);
                        break;
                    case 'type':
                        if (!isset($value['id'])) {
                            break;
                        }
                        $type = $this->getTypeById($value['id']);
                        $collection->setType($type);
                        break;
                    case 'changer':
                        $collection->setChanger($value);
                        break;
                    case 'creator':
                        $collection->setCreator($value);
                        break;
                    case 'properties':
                        $collection->setProperties($value);
                        break;
                }
            }
        }

        return $collection;
    }
296294
public <T extends DataSource> FutureData<ManagedSource> create(String name, T source) {
        return updateOrCreate(name, source, null);
    }
1187270
function(data, params, callback) {
			if (!data.name) {
				return callback({error:'name is required'});
			}
		  this.db.createCollection(data.name, {}, function(err, collection){
		  	var response = {
		  		name:collection.collectionName,
		  		_id:collection.collectionName
		  	};
				return callback(null, response);
		  });
		}
1355015
private function createCollection(DocumentManager $documentManager, ClassMetadata $classMetadata, $collectionName)
    {

        $database = $documentManager->getDatabase();

        $exists = false;
        foreach ($database->listCollections() as $collection) {
            if ($collection->getName() == $collectionName) {
                $exists = true;
            }
        }

        $creationOptions = $classMetadata->getCollectionCreationOptions();
        if (!empty($creationOptions) && !$exists) {
            $database->createCollection($collectionName, $creationOptions);
        }

        $collectionOptions = $classMetadata->getCollectionOptions();

        return $database->selectCollection($collectionName, $collectionOptions);
    }
162674
public function create($type, SourceDataFactoryInterface $dataFactory, $name)
    {
        if (is_string($type)) {
            $type = $this->typeRegistry->getType($type);
        }

        return new Source($type, $dataFactory, $name);
    }
1078661
public function update($collectionName, $data)
    {
        $sql = $this->dialect->grammarUpdate($collectionName, $data);

        $stid = oci_parse($this->raw, $sql);

        oci_bind_by_name($stid, ":id", $data['id']);

        foreach ($data as $key => $value) {
            oci_bind_by_name($stid, ":".$key, $data[$key]);
        }

        $result = oci_execute($stid);

        oci_free_statement($stid);

        return $result;
    }
247183
public function createCollectorResponse($collectorId, array $data = [])
	{
		return $this->sendRequest(
			$this->createRequest('POST', sprintf('collectors/%d/responses', $collectorId), [], $data)
		);
	}
874732
public function createCollectorForSurvey($surveyId, array $data = [])
	{
		return $this->sendRequest(
			$this->createRequest('POST', sprintf('surveys/%s/collectors', $surveyId), [], $data)
		);
	}
859739
public function findRelatedSourceRecords(int $sourceId, int $limit = null): array
    {
        /** @var Relations $relations */
        $relations = $this->framework->getAdapter(Relations::class);

        if (false === ($relation = $relations->getRelation($this->sourceTable, $this->sourceField))) {
            throw new \RuntimeException(\sprintf('The field %s.%s is not related', $this->sourceTable, $this->sourceField));
        }

        /** @var Model $relationsModel */
        $relationsModel = $this->framework->getAdapter(Model::class);

        $tagIds = $relationsModel->getRelatedValues($this->sourceTable, $this->sourceField, $sourceId);
        $tagIds = \array_values(\array_unique($tagIds));
        $tagIds = \array_map('intval', $tagIds);

        // Return if there are no tags
        if (0 === \count($tagIds)) {
            return [];
        }

        $query = \sprintf(
            'SELECT %s, COUNT(*) AS relevance FROM %s WHERE %s IN (%s) AND %s != ? GROUP BY %s ORDER BY relevance DESC',
            $relation['reference_field'],
            $relation['table'],
            $relation['related_field'],
            \implode(',', $tagIds),
            $relation['reference_field'],
            $relation['reference_field']
        );

        // Set the limit
        if ($limit > 0) {
            $query .= \sprintf(' LIMIT %s', $limit);
        }

        $related = [];

        // Generate the related records
        foreach ($this->db->fetchAll($query, [$sourceId]) as $record) {
            $related[$record[$relation['reference_field']]] = [
                'total' => \count($tagIds),
                'found' => $record['relevance'],
                'prcnt' => ($record['relevance'] / \count($tagIds)) * 100,
            ];
        }

        return $related;
    }
1019687
public function upsertDoc(string $collectionName, string $docId, array $docOrSubset): void
    {
        if ($this->hasDoc($collectionName, $docId)) {
            $this->updateDoc($collectionName, $docId, $docOrSubset);
        } else {
            $this->addDoc($collectionName, $docId, $docOrSubset);
        }
    }
63129
public static function retrieveSource($id, $sourceId, $params = null, $opts = null)
    {
        return self::_retrieveNestedResource($id, static::PATH_SOURCES, $sourceId, $params, $opts);
    }
873033
public function updateCollector($collectorId, array $data = [])
	{
		return $this->sendRequest(
			$this->createRequest('PATCH', sprintf('collectors/%s', $collectorId), [], $data)
		);
	}