$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]]]
- 1 回答
- 0 關注
- 127 瀏覽
添加回答
舉報
0/150
提交
取消