Integration of "LIKE" operator in the Selection query

Hello,
I take the liberty of writing to you, to ask for a favor.

I work with Cockpit CMS I want to know how to integrate the “LIKE” operator in a collection selection request in the case of a search. Here is my code :

$filter = [
“nom”=> $_REQUEST[‘client’]];
$resultats = $cockpit->module(‘collections’)->find(“clients”, [
“filter”=> $filter,
“sort”=>[’_o’=> 1],
“populate”=> 1,
“limit”=> 1
]);

This might depend on how your Cockpit instance is setup - “Lite” or “Db”.
I’m new to the CMS as well, so I’m only dabbling on what I can read from the source.

A) MongoLite

As far as I can tell there is no build-in option to use the LIKE operator.

But for the MongoLite db driver there is a filter option using regular expressions $regex that you might be able to utilize instead.

It is implemented in cockpit/Database.php at 568b0124352f6d27df359e8c19a70d2dd1961e87 · agentejo/cockpit · GitHub

B) MongoDB

The MongoDb driver uses the collection->find($filter) method.

While it also supports the $regex filter option, it might allow even more.
Have a look at https://docs.mongodb.com/manual/tutorial/query-documents/ to see all the different options on how to mold the $filter object in order to maybe achieve a LIKE request.

Though when searching the MongoDb docs it seems as if there is no LIKE operator but that $regex is actually the operator of choice for such a request.