0

I need to count the total users from users collection in phalcon that should not include some users.

I have query the result in mongo shell:

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

And it works fine.

But when i query using phalcon mongo model it return nothing. Is there anything i missed on the following query?

Users::count([
            'conditions' => [
                '_id' => [
                    ['$ne' => new \MongoId($user_id)]
                ]
            ]
        ]);
Bijesh Shrestha
  • 371
  • 2
  • 15

1 Answers1

1

Try the following:

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

Basically, you need an array to wrap the where clause. And if you prefer square brackets, try the following:

Users::count([
    [
        'conditions' => [
            '_id' => ['$ne' => new \MongoId($user_id)]
        ]
    ]
]);
Chin Leung
  • 14,621
  • 3
  • 34
  • 58