I need an advice about NoSQL/MongoDb and data/models structure

前端 未结 5 1137
醉梦人生
醉梦人生 2021-02-05 14:30

Recently I\'m exploring NoSQL Databases. I need an advice about how to store data in the most optimal and efficient way for a given problem. I\'m targeting MongoDB, now. However

5条回答
  •  难免孤独
    2021-02-05 15:12

    I would suggest storing votes as a list of story _ids in each user. That way you can find out what stories a user has voted for just by looking at the list. To get the users who have voted for a story you can do something like:

    db.users.find({stories: story_id})

    where story_id is the _id of the story in question. If you create an index on the stories field both of those queries will be fast.

提交回复
热议问题