为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

PHP
www说 2023-04-15 20:20:26
$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 字段的文档。
查看完整描述

1 回答

?
至尊宝的传说

TA贡献1789条经验 获得超10个赞

$text对使用文本索引索引的字段的内容执行文本搜索。

您不能$text在特定字段上使用。如果您使用$text,MongoDB 将搜索所有文本索引的字段。

所以你的命令不应该包括Client

['count' => $coll, 'query' => ['$text' => ['$search' => $Client]]]


查看完整回答
反对 回复 2023-04-15
  • 1 回答
  • 0 关注
  • 87 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信