【发布时间】:2021-04-08 14:31:05
【问题描述】:
我是 MongoDB 新手,我已经阅读了很多关于嵌入和引用文档的优缺点的建议,但找不到任何同时使用这两种方法的示例。例如,如果我想建立一个朋友列表,并且每次有人想看到他们的朋友列表时只想看到名字和头像,我可以将这些数据与朋友对象的 id 一起嵌入吗?这些数据是重复的,但会节省所需的查询次数。
person = {
_id: '123abv',
name: 'bob',
profilePic: '...',
...other props,
friends: [
{
_id: '124sdf',
name: 'tom',
profilePic: '...'
},
...other friends
]
}
【问题讨论】:
标签: mongodb mongodb-query schema