@param $collection
@param $id
@param array $fields

@return SerializableInterface|\Smartbox\CoreBundle\Type\SerializableInterface[]|void
160106
public function findOneById($collection, $id, array $fields = [])
    {
        try {
            $id = new \MongoDB\BSON\ObjectID((string) $id);
        } catch (\Exception $e) {
            return;
        }

        $queryOptions = new QueryOptions();
        $queryOptions->setQueryParams([
            '_id' => $id,
        ]);

        return $this->findOne($collection, $queryOptions, $fields);
    }
1046809
public function patchUser($id, array $fields)
    {
        $request = $this->client->patch($this->customer['url'].'/api/users/'.$id);

        $request->setAuth($this->customer['username'], $this->customer['password']);
        $request->setBody(json_encode($fields));

        $response = $request->send();

        return json_decode($response->getBody(true));
    }
94611
public static function getOne($id, $fields = null)
    {
        $table = self::getTableNameFromClass();

        if ($fields != null && is_array($fields)) {
            $query = "SELECT ". implode(', ', $fields) ." FROM $table WHERE id = $id";
        } else {
            $query = "SELECT * FROM $table WHERE id = $id";
        }

        $res = [];

        $results = Connection::db()->query($query);
        $results->setFetchMode(PDO::FETCH_ASSOC);

        while ($row = $results->fetch()) {
            array_push($res, $row);
        }

        if (!empty($res)) {
            return $res;
        } else {
            throw new PotatoException('There is no user with id '. $id);
        }
    }
629101
public function getEditForm($id = null, $fields = null)
    {
        $fields = FieldList::create();
        $modelClass = $this->request->getVar('others') ? 'others' : $this->modelClass;
        $classInst = Injector::inst()->get($this->modelClass);

        if (ClassInfo::hasMethod($classInst, 'getArchiveField')) {
            $listField = $classInst->getArchiveField();
            $fields->push($listField);
        } else {
            $otherVersionedObjects = $this->getVersionedModels('other');
            $modelSelectField = $this->getOtherModelSelectorField($modelClass);
            $fields->push($modelSelectField);

            // If a valid other model name is passed via a request param
            // then show a gridfield with archived records
            if (array_search($modelClass, $otherVersionedObjects)) {
                $listField = $this->createArchiveGridField('Others', $modelClass);

                $listColumns = $listField->getConfig()->getComponentByType(GridFieldDataColumns::class);
                $listColumns->setDisplayFields([
                    'Title' => _t(__CLASS__ . '.COLUMN_TITLE', 'Title'),
                    'Versions.first.LastEdited' => _t(__CLASS__ . '.COLUMN_DATEARCHIVED', 'Date Archived'),
                    'Versions.first.Author.Name' => _t(__CLASS__ . '.COLUMN_ARCHIVEDBY', 'Archived By'),
                ]);
                $listColumns->setFieldFormatting([
                    'Versions.first.LastEdited' => function ($val, $item) {
                        return DBDatetime::create_field('Datetime', $val)->Ago();
                    },
                ]);

                $fields->push($listField);
            }
        }

        $form = Form::create(
            $this,
            'EditForm',
            $fields,
            FieldList::create()
        )->setHTMLID('Form_EditForm');
        $form->setTemplate($this->getTemplatesWithSuffix('_EditForm'));
        $form->setAttribute('data-pjax-fragment', 'CurrentForm');
        $form->addExtraClass(
            'ArchiveAdmin discardchanges cms-edit-form cms-panel-padded center flexbox-area-grow '.
            $this->BaseCSSClasses()
        );
        $form->setFormAction(Controller::join_links(
            $this->Link($this->sanitiseClassName($this->modelClass)),
            'EditForm'
        ));

        $this->extend('updateEditForm', $form);

        return $form;
    }
159646
public function saveField($id, $field, $value) {
		$entity = [
			'id' => $id,
			$field => $value
		];
		return $this->saveArray($entity, ['accessibleFields' => ['id' => true]]);
	}
277808
public function find($criteria = [], array $fields = []) {
		$criteriaNormalized = $this->normalizeCriteria($criteria);
		
		$mongoCursor = $this->getAdapter()->find(
			$this->getTableName(),
			$criteriaNormalized,
			$fields
		);
		
		if ($criteria instanceof Criteria) {
			$this->applyCriteriaToCursor($criteria, $mongoCursor);
		}
		
		return $this->createResultset($mongoCursor);
	}
291235
public function select($collectionName, array $ids)
    {
        $mappedIds = array_map(function ($id) use ($collectionName) {
            return sprintf('%s:%s', $collectionName, $id);
        }, $ids);
        $params = ['foreign_ids' => join(',', $mappedIds)];
        $response = $this->doRequest('GET', 'meta/', $params);
        $body = $response->getBody()->getContents();
        return json_decode($body, true);
    }
713045
public static function field($name, $id = null)
    {
        return self::getInstance()
                     ->getBuilder(FieldBehavior::class)
                     ->field($name)
                     ->id($id);
    }
1108458
public function paginate($collection, $id = null)
    {
        $adapter = $this->adapterFactory->createAdapter($collection);

        $this->totalItems[md5($id)] = $adapter->getTotalResults();
        $offset = $this->calculateOffset($id);

        return $adapter->setOffset($offset)->setLength($this->getItemsPerPage($id));
    }
85247
public function postFields($id, array $fields, $guestSpaceId = null, $revision = -1): array
    {
        $options = ['json' => [
            'app' => $id,
            'properties' => $fields,
            'revision' => $revision
        ]];

        /** @var JsonStream $stream */
        $stream = $this->client
            ->post(KintoneApi::generateUrl('preview/app/form/fields.json', $guestSpaceId), $options)
            ->getBody();

        return $stream->jsonSerialize();
    }
813156
public function getUserByKey($id, $key, array $fields = [ ]) {
        $data = [
            'id' => $id,
            'key' => $key,
            'fields' => $fields
        ];
        return $this->apiGet('user', $data);
    }
646809
public function load($id, array $parameters = [], array $headers = [])
    {
        return $this->getFactory()->create(
            $this->getApi()->getList($id, $parameters, $headers)
        );
    }
427115
protected function copyCollectionWith(Collection $collection, array $values)
    {
        $collection = clone $collection;

        $collection->exchangeArray($values);

        return $collection;
    }
915072
public function hincrby($collection, $key, $field, $by = 1) {

        $current = $this->hget($collection, $key, $field, 0);
        $newone  = $current+$by;

        $this->hset($collection, $key, $field, $newone);

        return $newone;
    }
484049
public function fields($fields)
    {
        if (is_array($fields) || $fields === null) {
            $this->fields = $fields;
        } else {
            $this->fields = func_get_args();
        }
        return $this;
    }
153826
protected function resolveSelectiveFields(ICollection $collection, array $fields, array $types)
    {
        if (!count($fields)) {
            foreach ($types as $type) {
                $fields = array_merge($fields, $type->getFields());
            }

            if (!count($fields)) {
                $fields = $collection->getMetadata()
                    ->getFields();
            }
        }

        foreach ($fields as $fieldName => $field) {
            if ($field instanceof IRelationField && !$field instanceof BelongsToRelationField) {
                unset($fields[$fieldName]);
            }
        }

        return array_merge($collection->getForcedFieldsToLoad(), $fields);
    }
877191
public function iterator(array $fields = null)
    {
        return $this->mapper->collection(parent::iterator($fields), $this->definition);
    }