1

I am trying to select all different from "overview" in a mongodb collection. I use the query below but it does not work...

hist = db.find({'type':{$ne:'overview'}})

If I try without the $ne it works...

Any ideas on what is wrong?

Thanks!

Update

Just fixed... had to quote the "$ne"

5
  • Missing colon? :. I've never used mongodb, but googling the syntax for $neshowed me examples with that syntax. Commented Apr 27, 2014 at 17:38
  • sorry, the colon was missing here but not on the code... Commented Apr 27, 2014 at 17:42
  • And that why you should always copy-paste. Make it reproducable. Also, your new edit has the colon within the string, that's still wrong. Commented Apr 27, 2014 at 17:43
  • you are right... just fixed Commented Apr 27, 2014 at 17:44
  • So, your code is failing with the correct syntax? Commented Apr 27, 2014 at 17:44

2 Answers 2

0

You need to put quotation marks around $ne since pymongo uses dicts as parameters. It can't interpret { $ne : 'overview' } since $ne isn't a variable. Long story short, try this:

hist = db.find({'type':{'$ne':'overview'}})
Sign up to request clarification or add additional context in comments.

Comments

0

You're colon for $ne is inside the quotes, change to:

hist = db.find({'type':{$ne:'overview'}})

2 Comments

its like this and I keep getting syntax error everytime I put $ne or $all in a query...
Ahh, ok. One more thing though, i don't believe you need quotations around type, since you are not searching on a sub-document of type. try removing the single quotes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.