PHP MongoDB记录搜索问题

时间:2016-07-20 09:13:18

标签: php mongodb php-mongodb

我有MongoDB Collection以及以下数据

MongoDB Enterprise > db.UCODEPatter.find()
{ "_id" : { "UCODE" : NumberLong("233220524641368") }, "value" : 117 }
{ "_id" : { "UCODE" : NumberLong("233222325602424") }, "value" : 71 }
{ "_id" : { "UCODE" : NumberLong("233222325601932") }, "value" : 69 }
{ "_id" : { "UCODE" : NumberLong("233222325601947") }, "value" : 59 }
{ "_id" : { "UCODE" : NumberLong("233222325602414") }, "value" : 58 }
{ "_id" : { "UCODE" : NumberLong("233222325602419") }, "value" : 49 }
{ "_id" : { "UCODE" : NumberLong("233222325602418") }, "value" : 48 }
{ "_id" : { "UCODE" : NumberLong("233220535710165") }, "value" : 47 }
{ "_id" : { "UCODE" : NumberLong("233222325602405") }, "value" : 46 }
{ "_id" : { "UCODE" : NumberLong("233222325602420") }, "value" : 45 }
{ "_id" : { "UCODE" : NumberLong("233220537026120") }, "value" : 45 }
{ "_id" : { "UCODE" : NumberLong("233222686003297") }, "value" : 44 }
{ "_id" : { "UCODE" : NumberLong("233222325602417") }, "value" : 44 }

我使用下面的PHP代码进行数据搜索

<?php

        // Configuration
        $dbhost = 'localhost';
        $dbname = 'EIRLOGData';

        $m = new Mongo("mongodb://$dbhost");
        $db = $m->$dbname;

        $c_users = $db->UCODEPatter;

        $user = array(
                "_id" => "\"UCODE\" : NumberLong(\"233220524641368\")"    
        );

        $user = $c_users->findOne($user);
        var_dump($user);

?>

当我运行它时,它没有返回任何数据,请帮我排序

1 个答案:

答案 0 :(得分:0)

我不太清楚为什么要在{ "UCODE" : NumberLong("233220524641368") }, "value" : 117 }中存储_id,但您可以尝试以下操作:

$user = array(
  "_id.UCODE" => 233220524641368    
);