datatables-bundle
datatables-bundle copied to clipboard
I added a filter in MongoDBAdapter so the search no longer works !
error message : $or must be an array i can solve this problem when i change in MongoDBAdapter.
private function buildFilter(DataTableState $state): array { ++ $filter = []; -- $filter = $this->filters; if (!empty($globalSearch = $state->getGlobalSearch())) { foreach ($state->getDataTable()->getColumns() as $column) { if ($column->isGlobalSearchable()) { $filter[] = [$column->getField() => new \MongoDB\BSON\Regex($globalSearch, 'i')]; } } $filter = ['$or' => $filter]; } ++ $filter = array_merge($filter, $this->filters); return $filter; }
I don't understand the issue like this, seems like this is in how you use Mongo, not our bundle.
Hello @curry684
Today, we encountered the same error. We had a dataTable using MongoDBAdapter and a filter entry (see code below). The search was not working, but with the code of @SlimArfaaoui it works.
I can't really figure out what is the good way to use the filter entry otherwise....
->createAdapter(MongoDBAdapter::class, [
'collection' => $documentManager->getDocumentCollection(Page::class),
'filters' => [
'$and' => [
['type' => 'blog'],
['status' => ['$ne' => 'archive']]
]
]
])
`
``
Hello @curry684
I just added a simple filter in options MongoDbAdapter like this : $options = [ 'collection' => $collection, 'filters' => ['action' => $action] ];
and when i use global search i have this error "$or must be an array".
So when i followed the error i found in your bundle you collect filters configurated with global search inside $or like this : "$or" => array:10 [ "action" => "test" 0 => array:1 [ "id" => MongoDB\BSON\Regex {#1302 +"pattern": "aa" +"flags": "i" } ]
but when i use my solution (i set filters configurated outside $or) i will have this output for $filters : "$or" => array:8 [ 0 => array:1 [ "id" => MongoDB\BSON\Regex {#927 +"pattern": "aa" +"flags": "i" } ] . ... ] "action" => "test" ]
Stale issue message