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.