MongoDB.live, free & fully virtual. June 9th - 10th. Register Now

Efficient indexing for filtering with multiple fields

Hi,

I have a collection with more than 2 million documents with multiple fields, sample document:

{
	"_id" : ObjectId("5ec2dbe1ad29e4000c272d16"),
	"Name" : "aaa",
	"Age" : "56",
	"Status" : "Draft",
	"Direction" : "forward,
     <Other Fields>
}

What I want to achieve is filtering out with a number of fields, the problem is the filtering fields can be in any combination or any number of fields, eg, it can be either of:

{name:"aaa", Age:56, Direction:"Forward"}
{name:"aaa", Status:"Draft", Direction:"Forward"}
{Age:56, Status:"Draft"}

and any other combinations

Since I do not have compound indexes for every combination, querying is extremely slow

How do I create compound indexes to make this querying fast?