search

Home  >  Q&A  >  body text

Mongodb里我对于用户activities应该另建一个collection还是放在user collection里?

我需要跟用户呈现他活动的时间轴

现在有两种方案一种是,
把用户的活动放在user collection里,缺点是可能会放很多东西
另一种方案是,
新建一张activities collection,用userId做index
但其实我并不需要同时看多个用户的activities

巴扎黑巴扎黑2765 days ago576

reply all(1)I'll reply

  • 大家讲道理

    大家讲道理2017-04-21 11:18:18

    For your needs, it is recommended to add another collection and use userId for association, although mongodb gives priority to inline processing. Since analyzing your activities is used to create a user activity timeline, it is basically something every user should have. In addition, according to your description, activities will put a lot of things. Although MongoDB currently expands the size of a single document to 16M, if the content is too large, it will still exceed its limit, and it will also have a certain impact on queries, etc. For this situation, mongodb will also recommend making redundant connections to simulate SQL connection queries.

    reply
    0
  • Cancelreply