homelessDevOps
homelessDevOps

Reputation: 20726

Find Records in Mongo DB with PHP where ID != X

is it possible to find all records in an collection where the MongoID is not in an provided array?

Something like this (?):

        $search = array(
            '_id'    => array('$ne' => $ids) 
            'readby' => array('$ne' => $userId) // works
        );

Iam using PHP with the Mongo Extension.

Upvotes: 1

Views: 4364

Answers (1)

dcrosta
dcrosta

Reputation: 26258

Use $nin instead of $ne with arrays. Something like:

$search = array(
    '_id' => array('$nin' => $ids),
    'readby' => array('$ne' => $userId)
);

should do what you want.

Upvotes: 5

Related Questions