Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

mongodb

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?

like image 526
Diolor Avatar asked May 23 '14 06:05

Diolor


1 Answers

I think I found it. It needed $ne.

query = {
    "venue_id": venue_id,
    "status": {
         "$ne": 404
    } 
}
like image 71
Diolor Avatar answered Oct 06 '22 02:10

Diolor