search

Home  >  Q&A  >  body text

mongodb存放关系好还是直接存数据好?

比方说每条数据需要相关用户的信息,是存放user_id,每次读取时都去获取最新的用户信息,还是直接存放user对象的实际数据?

是时间换空间,还是空间换时间?

好纠结啊,大家一般怎么操作?

为情所困为情所困2792 days ago815

reply all(4)I'll reply

  • 迷茫

    迷茫2017-04-28 09:08:33

    If the user information will be updated, the user_id must be stored and then obtained separately (usually it has been obtained when the user logs in and cooperates with redis for storage calls). Also, do not ignore the storage read speed of mongodb. This is mongodb The advantage lies in. Personally speaking, all my projects store users separately and then call them through user id. for reference only.

    reply
    0
  • 淡淡烟草味

    淡淡烟草味2017-04-28 09:08:33

    It is indeed difficult to measure with a standard

    If you want to combine multiple tables, it will be a bit troublesome because it is an asynchronous operation.

    If you change relatively mundane data, use ID to associate it

    reply
    0
  • 曾经蜡笔没有小新

    曾经蜡笔没有小新2017-04-28 09:08:33

    Most of the time, user_id is stored, which is easier to manage

    reply
    0
  • 漂亮男人

    漂亮男人2017-04-28 09:08:33

    Of course you save the ID. Logically speaking, if the user logs out/is deleted/reported/has illegal content, but what you save is the actual data, how do you modify it then?

    reply
    0
  • Cancelreply