# Integration of "LIKE" operator in the Selection query

**URL:** <https://discourse.getcockpit.com/t/integration-of-like-operator-in-the-selection-query/1980>\
**Category:** General\
**Created:** [July 2, 2021, 10:54am UTC](https://discourse.getcockpit.com/t/integration-of-like-operator-in-the-selection-query/1980 "2021-07-02T10:54:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![arsenepoutsi](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/arsenepoutsi/32/746_2.png) [@arsenepoutsi](https://discourse.getcockpit.com/u/arsenepoutsi)\
**Post date:** [July 2, 2021, 10:54am UTC](https://discourse.getcockpit.com/t/integration-of-like-operator-in-the-selection-query/1980/1 "2021-07-02T10:54:46Z")

</div>

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  
]);

---

<div class="post-metadata">

**Author:** ![abernh](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/abernh/32/859_2.png) [@abernh](https://discourse.getcockpit.com/u/abernh)\
**Post date:** [July 7, 2021, 8:16am UTC](https://discourse.getcockpit.com/t/integration-of-like-operator-in-the-selection-query/1980/2 "2021-07-07T08:16:01Z")

</div>

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`](https://discourse.getcockpit.com/t/search-itens-by-term/70/3) that you might be able to utilize instead.

It is implemented in [cockpit/Database.php at 568b0124352f6d27df359e8c19a70d2dd1961e87 · agentejo/cockpit · GitHub](https://github.com/agentejo/cockpit/blob/568b0124352f6d27df359e8c19a70d2dd1961e87/lib/MongoLite/Database.php#L423)

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/](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.
