Sharding a collection with a 2d index and a regular index

45 views
Skip to first unread message

JP

unread,
Apr 23, 2012, 12:11:07 PM4/23/12
to mongod...@googlegroups.com
Hi!

I have a collection with a 2d index and a regular index. Right now it has ~6 million documents. All updates use the regular index but most queries use the 2d index. If I shard this collection using the regular index as the key, how does that affect the queries? Will it improve the queries performance or slow it down?

Thanks,

--
JP

Eliot Horowitz

unread,
Apr 24, 2012, 1:11:08 AM4/24/12
to mongod...@googlegroups.com
I don't think you can do that right now.
As a workaround, you can shard on ( 2dfield , _id )
That should make things work well in all cases.

> --
> You received this message because you are subscribed to the Google Groups
> "mongodb-user" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/mongodb-user/-/UnPZHIWxJ7AJ.
> To post to this group, send email to mongod...@googlegroups.com.
> To unsubscribe from this group, send email to
> mongodb-user...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/mongodb-user?hl=en.

JP

unread,
Apr 24, 2012, 11:15:27 AM4/24/12
to mongod...@googlegroups.com
If I use that key, I will have to use it in all updates as well, right?

--
JP


On Tuesday, April 24, 2012 2:11:08 AM UTC-3, Eliot Horowitz wrote:
I don't think you can do that right now.
As a workaround, you can shard on ( 2dfield , _id )
That should make things work well in all cases.

On Mon, Apr 23, 2012 at 12:11 PM, JP <jpaulo...@gmail.com> wrote:
> Hi!
>
> I have a collection with a 2d index and a regular index. Right now it has ~6
> million documents. All updates use the regular index but most queries use
> the 2d index. If I shard this collection using the regular index as the key,
> how does that affect the queries? Will it improve the queries performance or
> slow it down?
>
> Thanks,
>
> --
> JP
>
> --
> You received this message because you are subscribed to the Google Groups
> "mongodb-user" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/mongodb-user/-/UnPZHIWxJ7AJ.
> To post to this group, send email to mongod...@googlegroups.com.
> To unsubscribe from this group, send email to

A. Jesse Jiryu Davis

unread,
Apr 24, 2012, 11:42:53 AM4/24/12
to mongod...@googlegroups.com
The shard key must be included in all single-document updates (the default, as opposed to multi-updates).

JP

unread,
Apr 24, 2012, 12:24:30 PM4/24/12
to mongod...@googlegroups.com
Ok, but if I shard it using the regular index, the one I already use for the updates, will it still improve the queries? Like, will it split the work over the shards?

--
JP

A. Jesse Jiryu Davis

unread,
Apr 24, 2012, 12:34:32 PM4/24/12
to mongod...@googlegroups.com
Yes, mongos will distribute the query over the mongods which contain the data you're querying for.

JP

unread,
Apr 24, 2012, 12:51:41 PM4/24/12
to mongod...@googlegroups.com
Great! Thanks man!

--
JP
Reply all
Reply to author
Forward
0 new messages