Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
MongoDB3.6和PHP7.4:未知运算符$text_Php_Mongodb_Mongodb Query - Fatal编程技术网

MongoDB3.6和PHP7.4:未知运算符$text

MongoDB3.6和PHP7.4:未知运算符$text,php,mongodb,mongodb-query,Php,Mongodb,Mongodb Query,为什么此脚本抛出$text运算符未知的错误?如果我在其他字段上使用$gt或$eq,但语法相同,则它们可以工作。只要$text就行了 目标是统计包含“linux”内容的客户机字段的文档(例如linux-1、linux0.7等) 对使用文本索引索引的字段内容执行文本搜索 不能对特定字段使用$text。如果使用$text,MongoDB将搜索所有文本索引字段 因此,您的命令不应包括Client $connection = new MongoDB\Driver\Manager("mongodb://l

为什么此脚本抛出$text运算符未知的错误?如果我在其他字段上使用$gt或$eq,但语法相同,则它们可以工作。只要$text就行了

目标是统计包含“linux”内容的客户机字段的文档(例如linux-1、linux0.7等)

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

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

因此,您的命令不应包括
Client

 $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变量,它不应该只是“text”吗?如果确实在某处定义了$text,请使用不带撇号“”的$text。谢谢。仅当字段的值等于$Client value时,它才起作用。但我需要部分搜索。所以当$Client=“SiDock”有值“SiDock”、“SiDock1334”、“SiDockABC”时,我需要结果。我该怎么做?还有(将来)有没有办法更改我的代码,这样我就可以说:“where Client field在字符串中有*sometext”。在sql中,它将是>where Client like”%sometext%”签出,使用
$regex
,您可以查询一个特定的字段,就像前面尝试的那样。也可以签出
['count' => $coll, 'query' => ['$text' => ['$search' => $Client]]]