【问题标题】:How to count the total documents in phalcon mongodb collection如何计算 phalcon mongodb 集合中的文档总数
【发布时间】:2016-05-06 15:39:37
【问题描述】:

我需要从 phalcon 中的用户集合中计算不应该包括某些用户的用户总数。

我已经在 mongo shell 中查询了结果:

db.users.find({"_id": {"$ne": ObjectId("5704a9f3f0616e61138b4618")}}).count()

而且效果很好。

但是当我使用 phalcon mongo 模型进行查询时,它什么也不返回。以下查询有什么我遗漏的吗?

Users::count([
            'conditions' => [
                '_id' => [
                    ['$ne' => new \MongoId($user_id)]
                ]
            ]
        ]);

【问题讨论】:

    标签: php mongodb phalcon


    【解决方案1】:

    尝试以下方法:

    Users::count(array(
        array(
            'conditions' => array(
                '_id' => array('$ne' => new \MongoId($user_id))
            )
        )
    ));
    

    基本上,您需要一个数组来包装 where 子句。 如果您更喜欢方括号,请尝试以下操作:

    Users::count([
        [
            'conditions' => [
                '_id' => ['$ne' => new \MongoId($user_id)]
            ]
        ]
    ]);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-10
      • 1970-01-01
      相关资源
      最近更新 更多