如何查询MongoDB集合?

时间:2012-11-02 21:54:26

标签: php codeigniter mongodb

[_id] => MongoId Object (
    [$id] => 5090ace3788a466769b3804e
)
[startdate] => MongoDate Object (
    [sec] => 1301616000
    [usec] => 0
)
[enddate] => MongoDate Object (
    [sec] => 1304121600
    [usec] => 0
)
[your_id] => 33902
[odd_blah] => blahblah
[cam_id] => 339
[cost] => 0.01
[iscurrent] => 
[damn_current] => Array (
)

$coll = $this->mongo_db->where('cam_id', 339)->get('collection_name);

这不会返回任何内容。你可能会注意到我正在使用 https://github.com/alexbilbie/codeigniter-mongodb-library/tree/v2

我得到一个空数组。有人可以帮忙吗?这听起来很原始,但有点困在这里。

1 个答案:

答案 0 :(得分:2)

你非常接近,你需要将where语句放在一个数组中。

$coll = $this->mongo_db
    ->where(array('cam_id' => 339))
    ->get('collection_name');

我假设你正在使用Alex Bilbie的MongoDB CodeIgniter Library。他的文档确实已过时,因此建议查看他的source code的注释以及函数所需的输入类型。