我无法在phalcon的集合中查询%like

I use phalcon with mongo db. Model is Collection. I want use find to get

SELECT * FROM Users WHERE Username LIKE '%TienNguyen%'

I see in mongo db have query

b.users.find(
      { Username: /TienNguyen/ }
)

But in collection of Phalcon. How do I code it.

I tried Users::find([['Username' => "/TienNguyen/"]]); It is not working.

Please help me

As was mentioned above, regex searches that are not anchored at the beginning of the string can be very expensive because they require a full table scan. Depending on your use case you might consider using a text index instead. It provides support for case-insensitive non-anchored searches including suffix stemming.

Yeah, What you wanted was the $regex operator form instead of passing in a regex as a string. While that form works in the shell, most drivers are happier with the operator syntax:

Users::find([[ 'Username' => [ '$regex' => 'TienNguyen' ] ]])

Be very careful using $regex as the page suggests. You can ruin performance if you are not searching from the*start* of the string as in "^TienNguyen" using the caret operator.

For reference, just JSON decode any of the standard argument forms from the Mongo manual to get your language equivalent structure for most native driver functions.

You could do something like:

$Users = \Users::query()
            ->where(name LIKE :name:)
            ->bind(array('name' => '%' . $name . '%'))
            ->execute();

Please, try it:

Users::find([['Username' => new MongoRegex("/TienNguyen/")]]);

Good Luck!

Found a solution

 $objs = Items::find(
        [
            [                    
                'title' => [
                    '$regex' => $query,
                    '$options' => 'i'
                ]
            ]               
        ]
    );