我需要计算phalcon中用户集合的总用户数,其中不应该包括一些用户。
我在mongo shell中查询了结果:
db.users.find({"_id": {"$ne": ObjectId("5704a9f3f0616e61138b4618")}}).count()
而且效果很好。
但当我使用phalcon-mongo模型进行查询时,它什么也不返回。在下面的查询中,我遗漏了什么吗?
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)]
]
]
]);