Mongo Query question $gt,$lt

后端 未结 4 473
旧时难觅i
旧时难觅i 2020-12-09 08:19

I have a query below. I want get items between 4 and 6 so only a:1 should match because it has the value 5 in b.

> db.test.find({ b : { $gt :  4  }, b: {         


        
4条回答
  •  無奈伤痛
    2020-12-09 09:05

    Because you did not check the documentation.

    See

    http://www.mongodb.org/display/DOCS/Advanced+Queries

    and check for "ranges" on the page.

    Neither is your query syntax correct (compare against the example)

    nor does your "why a:2" part of the question make any sense since 'a' is not involved in your query. If you want to search for a:1 then you have to include it in your query.

    Keep in mind that all query clauses are AND combined by default unless you use the $or operator.

提交回复
热议问题