Diolor
Diolor

Reputation: 13450

MongoDB: Can't canonicalize query: BadValue $not needs a regex or a document

Some of my documents contain a field named status with the value 404. I do not wish to return those files, so I use the $not operator:

query = {
    "venue_id": venue_id,
    "status": {
         "$not": 404
    } 
}

However I get an error:

OperationFailure: database error: Can't canonicalize query: BadValue
$not needs a regex or a document

Does this happen because some of the docs have that field? I do not wish to use regex for speed reasons. How can I make this query correctly and efficiently?

Upvotes: 15

Views: 14115

Answers (1)

Diolor
Diolor

Reputation: 13450

I think I found it. It needed $ne.

query = {
    "venue_id": venue_id,
    "status": {
         "$ne": 404
    } 
}

Upvotes: 32

Related Questions