【发布时间】:2013-08-07 03:26:40
【问题描述】:
问题
简而言之,我的问题是:当文档中的数组发生更改时,用户会收到新数组,还是仅收到更改?
如果这个问题不清楚,我在下面描述了我的问题。
问题
我有一个集合,其文档包含一个数组字段,两个用户将向其中推送值。此集合中的文档如下所示:
var document = {
userId1: "...user id...", // The id of the first of the two users.
userId2: "...user id...", // The id of the second of the two users.
data: [] // The field the two users will push values to.
}
data 一开始是空的,然后用户将轮流向它推送值。
当其中一个用户向data 推送某个值时,服务器会将更改发送给第二个用户。第二个用户会收到整个data-array,还是只收到更改(推送的值)?我有点担心第二个用户会收到整个data-array,即使它只是一个被推送到它的值,如果data包含很多值,我担心这会成为一个瓶颈.
是这样吗?如果是这样,使用另一个集合来存储值将解决它,对吗?像这样的:
var document = {
id: "...unique id...",
userId1: "...user id...", // The id of the first of the two users.
userId2: "...user id..." // The id of the second of the two users.
}
var documentData = {
idReference: "...the unique id in the document above...",
value: "...a value..."
}
不要将值推入document 中的数组,而是将它们插入包含documentData 的集合中。这(我知道)不会有我担心第一个解决方案的缺点(但如果它没有缺点,我宁愿使用第一个解决方案)。
【问题讨论】:
-
您可以通过关注these instructions 来查看 websocket 连接中的帧,从而仔细检查到底发生了什么。
标签: arrays mongodb collections meteor field