Question: Is tip #25 in *Tips and Tricks for MongoDB Developers* correct?

It says that this query:

```
collection.find({"x" : criteria, "y" : criteria, "z" : criteria})

```

can be optimized with

```
collection.ensureIndex({"y" : 1, "z" : 1, "x" : 1})

```

I think it's false because for this to work, x should be in front. I thought the order of indexes matter.

So where did I go wrong?

Answer: 
The order of the fields in the index only matters if the query doesn't include all of the fields in the index. This query is referencing all three fields so the order of the fields in the index doesn't matter.

See more details in [the docs on compound indexes](http://docs.mongodb.org/manual/core/indexes/#compound-indexes).

The *order* of the fields in the `find` query object is not relevant.
The books states the below scenario

You have 3 queries to run: 

```
Collection.find({x:criteria, y:criteria,z:criteria})  
Collection.find({z:criteria, y:criteria,w:criteria})  
Collection.find({y:criteria, w:criteria })  

```

To use 

```
collection.ensureIndex({y:1,z:1,x:1})  

```

it is considering the occurrence and as occurrence of y is more, it want all the queries to hit y followed by z and lastly as you will be running the 1st query a thousand times more than the other two hence including x, if this was not the case and you run all 3 queries equally then the suggestion is 

```
Collection.ensureIndex({y:1,w:1,z:1}) . 

```

Moreover as per the MongoDB documentation **“The order of fields in a compound index is very important.”** But in the above case scenario the use case is different. It is trying to optimize all the use case queries with one index.