<?php


namespace App\Models\demo\mongo;


use Api\PhpUtils\Mongo\MongoBase;

class Test extends MongoBase
{

    protected function getConfigIndex()
    {
        return "demo";
    }

    protected function getDatabaseName()
    {
        return "demo";
    }

    protected function getCollectionName()
    {
        return "user";
    }

    protected function getWhere($params)
    {
        return $params;
    }

    protected function getQueryOptions($fields = [], $sort = [], $limit = [])
    {
        $options = [
            'maxTimeMS' => 800,
            'limit' => 100
        ];
        if (is_array($fields) && !empty($fields)) {
            $options['projection'] = $fields;
        }
        if (is_array($sort) && !empty($sort)) {
            $options['sort'] = $sort;
        }
        if (is_array($limit)) {
            if (isset($limit['start'])) {
                $options['skip'] = intval($limit['start']);
            }
            if (isset($limit['count'])) {
                $options['limit'] = intval($limit['count']);
            }
        }
        return $options;
    }
}
