Followers - mongodb database design

后端 未结 4 853
情话喂你
情话喂你 2020-12-14 12:19

So I\'m using mongodb and I\'m unsure if I\'ve got the correct / best database collection design for what I\'m trying to do.

There can be many items, and a user can

4条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-14 12:38

    Unfortunately NoSQL databases aren't eligible in this case. Your data model seems exact relational. According to MongoDB documentation we can do only these and can perform only these.

    There are some practices. MongoDB advises to us using Followers collection to get which user follows which group and vice versa with good performance. You may find the closest case to your situation on this page on slide 14th. But I think the slides can eligible if you want to get each result on different page. For instance; You are a twitter user and when you click the followers button you'll see the all your followers. And then you click on a follower name you'll see the follower's messages and whatever you can see. As we can see all of those work step-by-step. No needed a relational query.

    I believe that you should not use unbound arrays (where the limit is unknown) due to performance issues when the document has to be moved because of its expanding size. (Is there a recommended maximum for array lengths before hitting performance issues anyway?)

    Yes, you're right. http://askasya.com/post/largeembeddedarrays . But if you have about a hundred items in your array there is no problem. If you have fixed size some data thousands you may embed them into your relational collections as array. And you can query your indexed embedded document fields rapidly.

    In my humble opinion, you should create hundreds of thousands test data and check performances of using embedded documents and arrays eligible to your case. Don't forget creating indexes appropriate your queries. You may try to using document references on your tests. After tests if you like performance of results go ahead..

    You had tried to find group_id records that are followed by a specific user and then you've tried to find a specific item with those group_id. Would it be possible Item_Groups and Followers collections have a many-to-many relation? If so, many-to-many relation isn't supported by NoSQL databases.

    Is there any chance you can change your database to MySQL?

    If so you should check this out.

    briefly MongoDB pros against to MySQL;
    - Better writing performance
    
    briefly MongoDB cons against to MySQL;
    - Worse reading performance
    

    If you work on Node.js you may check https://www.npmjs.com/package/mysql and https://github.com/felixge/node-mysql/

    Good luck...

提交回复
热议问题