There is no suitable formula for manipulating many-to-many relationships in MongoDB. Therefore, I combined the collections as inline documents, as shown below. But the most important indexes are created in this case. For example, if you want to request the followingClubs , you should create an index, such as schema.index({ 'followingClubs._id':1 }) , using Mongoose. And if you want to query country and followingClubs , you have to create another index, for example schema.index({ 'country':1, 'followingClubs._id':1 })
Pay attention when working with embedded documents: http://askasya.com/post/largeembeddedarrays
Then you can quickly get your documents. I tried to get the score of 150,000 records using this method, it took only 1 second. This is enough for me ...
ps: we do not forget that in my tests, my Users collection never experienced data fragmentation. Therefore, my queries can demonstrate good performance. Especially, the followingClubs array of embedded documents.
User collection
{ "_id": "1", "fullname": "Jared", "country": "USA", "followingClubs": [ {"_id": "12"} ] }
Club Collection
{ "_id": "12", "name": "A famous club" }
efkan
source share