Sparse Indexes on sharded collections

27 views
Skip to first unread message

Tim Haines

unread,
Mar 25, 2014, 6:54:38 PM3/25/14
to mongod...@googlegroups.com
Hi there,

We have a multi-tenant database, with a particular collection sharded by orgId.  We want to add a remindAt date to some of the documents (< 1%), and have a sparse index on it.

This collection already has multiple indexes on it, always including the orgId.

Queries that run on the remindAt field won't include the orgId in the selector.  Do I need to include the orgId in the sparse index on remindAt or does mongo allow me to leave it off?   

Whether I add the orgId field or not, all queries that run on the remindAt field that aren't orgId specific need to be distributed out to every shard, correct?  If that's the case, it may be better not to add the orgID if mongo allows that.

Another way of modeling this may be to keep the remindAt dates in a different collection, but I doubt the benefits are worthwhile.

Cheers,

Tim.

Asya Kamsky

unread,
Mar 26, 2014, 6:50:36 AM3/26/14
to mongodb-user
You do not need to have the shard key as part of your index on remindAt date, but you are correct that queries that only query on remindAt will be scatter-gather.

Keep in mind that only single field indexes can be sparse (meaningfully).  If you *were* to index on orgId, remindAt and made it sparse, it would be guaranteed to index every single document, because the shard key must always be set.

Asya



--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
 
For other MongoDB technical support options, see: http://www.mongodb.org/about/support/.
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.
To post to this group, send email to mongod...@googlegroups.com.
Visit this group at http://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/8b1a7ba6-187b-4f9d-bbf5-ca4845366be6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Tim Haines

unread,
Mar 26, 2014, 12:47:35 PM3/26/14
to mongod...@googlegroups.com
Thanks Asya, this is very helpful.   Are these details documented somewhere?  I'd love to gain a more thorough understanding here and have official documentation to reference.

Tim.

Asya Kamsky

unread,
Mar 28, 2014, 7:13:45 AM3/28/14
to mongodb-user
Sometimes the problem is there is too much stuff documented :) :) :)

Which part in particular were you referring to? I think everything I
said is in the docs at http:///docs.mongodb.org though it's possible
that some limitations are described in more detail in related Jira
tickets...

Asya
> https://groups.google.com/d/msgid/mongodb-user/8bf17782-25a1-4e82-9d02-df38c4e80ec3%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages