1
executeQueryを使用して_idを検索したいmongodb driver php。ここで_idを使ってMongodb PHPを検索するとエラーが発生する
はユーザーコレクション
{
"_id" : ObjectId("55ad0bd1032e1b12088b46a8"),
"email" : "[email protected]"
}
の私の文書構造であると、私のPHPコードは
<?php
//Getting object id
$id = new MongoId("55ad0bd1032e1b12088b46a8");
//filtering
$filter = ['_id' =>$id];
$options = [];
// Adding query
$query = new MongoDB\Driver\Query($filter, $options);
$manager = new MongoDB\Driver\Manager("mongodb://localhost:27017");
$cursor = $manager->executeQuery('db.users', $query);
私はそれを実行したときに、私はすべてのエラー
PHP Fatal error: Uncaught exception 'MongoDB\Driver\Exception\ConnectionException' with message 'unknown operator: $id' in /test.php:27 Stack trace: 0 /test.php(27): MongoDB\Driver\Manager->executeQuery('db.users', Object(MongoDB\Driver\Query)) 1 {main} thrown in test.php on line 27
を次しまっています助けて?
を働いているにConnectionExceptionであることを奇妙です。 27行はどちらですか? また、MongoDBのPHP拡張モジュール(Mongo拡張モジュールではない)を使用しているので、MongoIdの代わりに '' ObjectID''を使うべきです。 http://php.net/manual/en/class.mongodb-bson-objectid.php –