0

I have a collections in mongodb: user collection

{
_id:xxxxxx,
friendList:[12345,67899,57889],//list of ids of friends
readBooks:[bookid1,bookid2],
wanttoread:[bookid5,bookid6]
}

friends collection

{ _id:12345,
readBooks:[bookid3,bookid5],
wantToread:[bookid1]}

I have another collection books which gives the name and details of a book for the id. I want to do sharding for this in mongodb, based on readBook or wanttoread. If they have the same books, the data goes to the same shard.

I searched about this, but I couldn't find a way to shard based on array. Is there any way i can do it? or do I need to create another collection like

 {id: userid or friend id,bookId:bookid}

and shard based on bookId.

4

1 回答 1

0

您只能使用一个 shard key,并且您选择一个后无法更改它。

我建议对具有最大基数(最大数量的文档)的 collection-id 进行分片。

MongoDB分片

于 2013-04-30T19:42:54.443 回答