MongoDB: "Unsupported projection option: pop: { $gt: 0.0 }" (debugging)

16,080

Mongodb's find function takes two arguments, query and projection. The query that you are firing is having two objects, second being considered as projection criteria.

Your query should hold all the criteria in single object.

db.zips.find({
               "state":"GA", 
               "pop":{$gt:0}
            })
       .sort({pop:1})
       .limit(5)
Share:
16,080
Admin
Author by

Admin

Updated on June 08, 2022

Comments

  • Admin
    Admin almost 2 years

    I'm trying to run this query:

    db.zips.find({"state":"GA"}, {"pop":{$gt:0}}).sort({pop:1}).limit(5)
    

    But I keep getting this error:

    "errmsg" : "Unsupported projection option: pop: { $gt: 0.0 }"
    

    When I run this query, it works perfectly:

    db.zips.find({"state":"GA"}).sort({pop:1}).limit(5)
    

    I'm trying to find the fields where "state" = "GA" and then where "pop" is greater than 0 and limit it to 5 results and sort them in ascending order.

    When I put the {"pop":{$gt:0}} part as the first argument in the find function, it runs, but it ignores the fact that I only want states that equal "GA". I'm not sure how to fix this, does anyone know what's wrong?