;
    

###  Node.js

    
    
    const querySnapshot = await db.collection('employees')
                                  .where("salary", ">", 100000)
                                  .orderBy("salary")
                                  .get();
    
    // Order results by `experience`
    

###  Python

    
    
    results = db.collection("employees")
                .where("salary", ">", 100000)
                .order_by("salary")
                .stream()
    
    // Order results by `experience`
    

While adding an ordering on ` experience ` to the query will yield the same
set of documents and obviate re-ordering the results on the clients, the query
may read many more extraneous index entries than the earlier query. This is
because Cloud Firestore always prefers an index whose index fields prefix
match the order by clause of the query. If ` experience ` were added to the
order by clause, then Cloud Firestore will select the ` (experience [...],
salary [...]) ` index for computing query results. Since there are no other
constraints on ` experience ` , Cloud Firestore will read **all** index
entries of the ` employees ` collection before applying the ` salary ` filter
to find the final result set. This means that index entries which don't
satisfy the ` salary ` filter are still read, thus increasing the latency and
cost of the query.

##  Pricing

Queries with range and inequality filters on multiple fields are billed based
on documents read and index entries read.

For detailed information, see the [ Pricing ](/docs/firestore/pricing) page.

##  Limitations

Apart from the [ query limitations ](/docs/firestore/query-
data/queries#query_limitations) , note the following limitations before using
queries with range and inequality filters on multiple fields:

  * Queries with range or inequality filters on document fields and only equality constraints on the document key ` (__name__) ` are not supported. 
  * Cloud Firestore limits the number of range or inequality fields to 10. This is to prevent queries from becoming too expensive to run. 

##  What's Next

  * Learn about [ optimizing your queries ](/docs/firestore/query-data/multiple-range-optimize-indexes) . 
  * Learn more about [ performing simple and compound queries ](/docs/firestore/query-data/queries) . 
  * Understand how [ Cloud Firestore uses indexes ](/docs/firestore/concepts/index-overview) . 

Send feedback

Except as otherwise noted, the content of this page is licensed under the [
Creative Commons Attribution 4.0 License
](https://creativecommons.org/licenses/by/4.0/) , and code samples are
licensed under the [ Apache 2.0 License
](https://www.apache.org/licenses/LICENSE-2.0) . For details, see the [ Google
Developers Site Policies ](https://developers.google.com/site-policies) . Java
is a registered trademark of Oracle and/or its affiliates.

Last updated 2024-04-17 UTC.

[{ "type": "thumb-down", "id": "missingTheInformationINeed", "label":"Missing
the information I need" },{ "type": "thumb-down", "id":
"tooComplicatedTooManySteps", "label":"Too complicated / too many steps" },{
"type": "thumb-down", "id": "outOfDate", "label":"Out of date" },{ "type":
"thumb-down", "id": "samplesCodeIssue", "label":"Samples / code issue" },{
"type": "thumb-down", "id": "otherDown", "label":"Other" }]  [{ "type":
"thumb-up", "id": "easyToUnderstand", "label":"Easy to understand" },{ "type":
"thumb-up", "id": "solvedMyProblem", "label":"Solved my problem" },{ "type":
"thumb-up", "id": "otherUp", "label":"Other" }]  Need to tell us more?

  * ###  Learn 

    * [ Guides ](/docs/guides/)
    * [ Reference ](/docs/reference/)
    * [ Samples ](/docs/samples/)
    * [ Libraries ](/docs/libraries/)
    * [ GitHub ](//github.com/firebase/)
  * ###  Stay connected 

    * [ Blog ](//firebase.blog)
    * [ Firebase Summit ](/summit/)
    * [ Twitter ](//twitter.com/Firebase)
    * [ YouTube ](//www.youtube.com/user/Firebase)
  * ###  Support 

    * [ Contact support ](/su