【问题标题】:How to limit _id field to return in MongoDB use Thinkphp/PHP?如何限制 _id 字段在 MongoDB 中返回使用 Thinkphp/PHP?
【发布时间】:2014-09-01 07:52:26
【问题描述】:

我使用 Thinkphp 开发一个 web 项目。现在我需要查询具有指定字段的 mongodb 并禁止 '_id' 字段。但是 '_id' 字段默认包含在结果集中。我知道在 mongodb 客户端可以使用按照代码抑制'_id'字段,但是使用PHP/Thinkphp呢?

db.inventory.find( { type: 'food' }, { _id:0 } )

【问题讨论】:

标签: php mongodb thinkphp


【解决方案1】:

可以使用MongoModel进行查询,用法类似Mysql Model。

M('CollectionName')->where(array('type'=>'food'))->field('_id')->select();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-22
    • 2018-05-15
    • 1970-01-01
    • 2018-09-07
    • 1970-01-01
    相关资源
    最近更新 更多