Single vs compound index speed

I currently have these two indexes:
db.collection.createIndex({ guildID: 1 })
db.collection.createIndex({ userID: 1 })

My most common query to my database is { guildID: 'string', userID: 'string' }

Should I make a compound index of db.collection.createIndex({ guildID: 1, userID: 1 })? Or would having two single indexes be faster?

With 2 single field indexes, only one will be used to satisfy the query. Documents will have to be fetched to verify if the other field matches.

With a compound index of the 2 fields, the index can be used to satisfied the whole query. Only documents matching the whole query will be fetch.

Depending on other queries you might be better off with an index {userID: 1, guildID : 1}.

3 Likes