MongoDB - is DBREF necessary?

前端 未结 3 641
無奈伤痛
無奈伤痛 2020-12-01 05:17

Using the DBREF datatype in MongoDB, a document may look like as shown below. But having the $ref field in every row feels redundant as every row obviously poin

3条回答
  •  北荒
    北荒 (楼主)
    2020-12-01 05:52

    From the docs:

    Manual references are an alternative, and the docs say manual references are preferable to DBREFs (though I'm not sure why). DBREFs are helpful when the referenced object lives in another database or where the collection name would not otherwise be obvious.

    Denormalization/embedding is preferable to any kind of linking because then you get atomic updates and don't need to re-query for the related data.

提交回复
热议问题