$connection = new MongoDBDriverManager("mongodb://localhost:27017");
$db = "db";
$coll = "calls";
$filter = [];
$options= [];
$coll = "calls";
$Client= "linux";
$query = new MongoDBDriverCommand(['count' => $coll, 'query' => ['Client' => ['$text' => ['$search' => $Client]]]]);
$result = $connection->executeCommand($db,$query);
$res = current($result->toArray());
$countAll = $res->n;
echo ("Total linux clients "Unknown": " . $countAll . "n");
为什么此脚本会抛出运算符未知$text错误? 如果我在其他字段上使用 $gt 或 $eq 但语法相同,它们就可以工作。只是$text不会。
目标是计算具有"linux"内容"的客户端字段的文档(例如linux-1、linux0.7等(。
$text对
使用文本索引编制索引的字段的内容执行文本搜索。
不能对特定字段使用$text
。如果您使用$text
,MongoDB 将搜索所有文本索引的字段。
因此,您的命令不应包含Client
['count' => $coll, 'query' => ['$text' => ['$search' => $Client]]]