喜欢php mongodb中的查询[重复]

This question already has an answer here:

I am trying to implement MySQL like query in mongo db with PHP but I don't know how to do that.

select * from stud where name like "%abc%"

php code:

$regex = new \MongoDB\BSON\Regex("^(.*?(\abc\b)[^$]*)i$"); 
$result = $db->stud->find(array('name' => $regex));

I also Tried this

$result = $db->stud->find(( { name : { $regex: '*.abc.*'} } ));
</div>

According to this manual to perform a LIKE match you don't need to use wildecards anywhere in pattern. For example to query %abc% you have to do this:

$result = $db->stud->find(array(
    'name' => new \MongoDB\BSON\Regex("abc")
));