Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Collection::findFirst is returning a document when criteria specified does not match

I have a document:

_id: <object_id>
user_id: 123

When I use findFirst to find a document with a user id that does not exist:

 Users::findFirst(array("user_id" => 9867));

I find it returns the only document that exists when I need false. Is this expected behaviour?


It must be an array of an array:

    array("user_id" => 9867)

edited Apr '16

The problem is still exists for me.

$entity = Post::findFirst(123123); // $entity = false
$entity = Post::findFirst("id=123123"); // $entity = false
$entity = Post::findFirst(array("id" => 123123)); // $entity - first founded post in my DB
$entity = Post::findFirst(array(array("id" => 123123))); // $entity - Also first founded post in my DB

@khaxel you're mixing the way of querying data using the ORM in the ODM, please check the docs