带有 PHP 7.4 的 MongoDB 3.6:未知运算符 $text

$connection = new MongoDB\Driver\Manager("mongodb://localhost:27017");

  $db = "db";

  $coll = "calls";

  $filter = [];

  $options= [];

  $coll = "calls";

  $Client= "linux";

  $query = new MongoDB\Driver\Command(['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 operator is unknown 的错误?如果我在其他字段中使用 $gt 或 $eq 但语法相同,它们就可以工作。只有 $text 不会。


目标是统计具有内容为“linux”(例如linux-1、linux0.7等)的 Client 字段的文档。


www说
浏览 90回答 1
1回答

至尊宝的传说

$text对使用文本索引索引的字段的内容执行文本搜索。您不能$text在特定字段上使用。如果您使用$text,MongoDB 将搜索所有文本索引的字段。所以你的命令不应该包括Client['count' => $coll, 'query' => ['$text' => ['$search' => $Client]]]
打开App,查看更多内容
随时随地看视频慕课网APP