Q:

Is a compound index needed for querying on one field and using another for sorting?

In MongoDB, let's say I have the following query:
db.things.find({ name: 'some string' }).sort({ age: -1 })

I know that having an index for age will help performance, but do I create the indexes for name and age separately, or as a compound?
db.things.createIndex({ name: 1, age: -1 })

A:

Create a compound index.  Mongo DB's documentation goes into more detail here:
https://docs.mongodb.com/manual/tutorial/sort-results-with-indexes/
From that page:

The following operations can use the index to get the sort order: 
...
db.data.find( { a: 5 } ).sort( { b: 1, c: 1 } ) -----------------------------------   { a: 1 , b: 1, c: 1 }

