如何计算 phalcon mongodb 集合中的文档总数

How to count the total documents in phalcon mongodb collection

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

我在mongoshell中查询了结果:

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

而且效果很好。

但是当我使用 phalcon mongo 建模时,它 return 什么也没有。我在以下查询中遗漏了什么吗?

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

尝试以下操作:

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

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

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