I have a really simple MongoDB collection:
{
"user": 1,
"domain": "example.com",
"apiAccess": true
}
There's an index on the "user" and "domain" fields. I always perform the same type of query on this collection and it only ever returns one result.
db.collection.find({"user" 1, "domain": "example.com"});
What I realised is because I always query on "user" and "domain" and because together they're unique I could just combine the field into one field. And I could make this the _id like so:
{
"_id": "example.com_1",
"apiAccess": true
}
This way I only query on one field and only need one index. I was thinking this would perform better due to these reasons however due to my limited understanding of MongoDB I'm unsure if this would be the case and I was wondering if someone could shed some light.