robsonvn / laravel-couchdb

A CouchDB based Eloquent model and Query builder for Laravel
56 stars 28 forks source link

QueryException no-index or no matching fields order/selector #12

Closed edukmattos closed 6 years ago

edukmattos commented 6 years ago

Hi ! Im using this package with l5-reposytory.

When runnig: localhost:8000/states

Im getting an error message below:

(1/1) Exception QueryException no-index or no matching fields order/selector

in Builder.php (line 358)

at Builder->get(array('')) in Builder.php (line 462) at Builder->getModels(array('')) in Builder.php (line 446) at Builder->get() in Model.php (line 1374) at Model->call('get', array()) in Model.php (line 568) at Model->call('get', array()) in StateRepositoryEloquent.php (line 25) at StateRepositoryEloquent->allStates() in StatesController.php (line 29) at StatesController->index() at call_user_func_array(array(object(StatesController), 'index'), array()) in Controller.php (line 55)

StatesController.php <?php

namespace MyApp\Http\Controllers;

use Illuminate\Http\Request;

use MyApp\Http\Requests; use MyApp\Http\Controllers\Controller; use MyApp\Repositories\StateRepository;

class StatesController extends Controller { private $stateRepository;

public function __construct(StateRepository $stateRepository)
{
    $this->stateRepository = $stateRepository;
}

/**
 * Display a listing of the resource.
 *
 * @return Response
 */
public function index()
{
    #$this->authorize('regions-index');

    **$states = $this->stateRepository->allStates();**

    dd($states);

    return view('states.index', compact('states'));
}

StateRepositoryEloquent.php <?php

namespace MyApp\Repositories; use MyApp\Models\State; use Prettus\Repository\Eloquent\BaseRepository;

class StateRepositoryEloquent extends BaseRepository implements StateRepository { public function model() { return State::class; }

private $state;

public function __construct(State $state)
{
    $this->state = $state;
}

**public function allStates()
{
    return $this->state->get();
}**

public function findStateById($id)
{
    return $this->state->find($id);
}

public function storeState($input)
{
    $state = $this->state->fill($input);
    $state->save();
}

}

-------------------------------------------------------------------------------------------------------------------------------------------

web.php

Route::group(['prefix' => 'states'], function () { Route::get('/', 'StatesController@index')->name('states'); Route::get('/create', 'StatesController@create')->name('states.create'); Route::get('/{id}/show', 'StatesController@show')->name('states.show'); Route::get('/{id}/edit', 'StatesController@edit')->name('states.edit'); Route::get('/{id}/destroy', 'StatesController@destroy')->name('states.destroy'); Route::put('/{id}/update', 'StatesController@update')->name('states.update'); Route::post('/', 'StatesController@store')->name('states.store'); }); #

edukmattos commented 6 years ago

Hi! I had new tests without the package l5-repository and the same error message. This package only works with couchdb 2.0?

robsonvn commented 6 years ago

Hi @ecmattos, which version are you using? This package is working with all 2.x versions. This index problem might be related to user permission, usually only admin can create indexes and this library creates index on the fly.

edukmattos commented 6 years ago

Oi, Robson ! Eu atualizei o meu CouchDB para a versao 2 e funcionou beleza ! Vou testar a autenticações dos usuários e qualquer coisa, peço uma ajuda. Abraçoes

robsonvn commented 6 years ago

Hi @ecmattos I'm glad you got it sorted. In any further request, please let's keep talking in English so we can help other users which may face the same problem as you.

edukmattos commented 6 years ago

ok

diegonella commented 6 years ago

I Solved with: curl -X POST -d'{"index":{"fields":["type"]}}' -H 'Content-type: application/json' https://user:password@host.com/database_name/_index