Indexes and multi-tenant applications in mongodb

169 views
Skip to first unread message

mguserdev

unread,
Oct 29, 2011, 12:17:36 PM10/29/11
to mongodb-user
I am working on a multi-tenant application in which I am using a
single collection for all tenants and tracking the tenant via a
tenant_id field. All queries will include tenant_id = X as a
condition.

My question is that I've read mongodb can only use a maximum of 1
index per query. So, if an every query I already have tenant_id = X as
a condition, then that means none of my other field's indexes will
ever be used?

EG: Suppose I had a query in which tenant_id = X and foo = bar, if
mongodb is using the index on tenant_id, then I creating an index on
the 'foo' field will never be used?

Is there a best practice to deal with indexing fields in multi-tenant
applications in mongodb?

Karl Seguin

unread,
Oct 30, 2011, 1:34:09 AM10/30/11
to mongod...@googlegroups.com
compound indexes are you friend.

createIndex({tenant_id: 1, foo: 1})


Might help.

Karl
Reply all
Reply to author
Forward
0 new messages