蒙戈数据库.如何查找包含所有子字符串的字符串


MongoDB. How to find a string having all substrings?

我有MongoDB文档。所有文档都包含一个全名字符串(例如"John Fidgerald Kennedy"、"john doe"(。

在包含子字符串(例如"john","kennedy

"或"kennedy","john"(的网络查询中,我想找到全名字符串包含所有这些子字符串的所有文档(例如"John Fidgerald Kennedy"(。

但是,我不知道该怎么做。

基本上,对于PHP,我想做一些类似$collection->find(array("fullname" => "john" && "kennedy"(之类的事情。我知道这种语法是不可能的,但它是为了给出我想要的想法。

知道怎么做吗?理想情况下,鉴于我有超过 1000000 个文档,我想要一种快速的方法。

我希望这对您有所帮助:

$query = "john";
$where = array(array('fullname'  => array('$regex' => new MongoRegex("/$query/i"))));
$mongoClient = new MongoClient();
$db = $mongoClient->selectDB("datbase_name");
$collection = $db->selectCollection("collection_name");
$cursor = $collection->find($where);