MongoDB: Cannot canonicalize request: BadValue $ does not need regular expression or document

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

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

However, I get an error message:

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

Does this happen because some of the documents have this field? I do not want to use regex for speed reasons. How can I make this request correctly and efficiently?

+8
mongodb
source share
1 answer

I think I found it. He needed $ne .

 query = { "venue_id": venue_id, "status": { "$ne": 404 } } 
+20
source share

All Articles