1

The question

In short, my question is: when an array in a document is changed, will the users receive the new array, or just the changes?

If that question is unclear, I've described my problem below.

The problem

I have a collection whose documents contain an array field two users will push values to. A document in this collection kind of looks like this:

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 will from the beginning be empty, and the users will then take turns pushing values to it.

When one of the user pushes some value to data, the server will send the changes to the second user. Will the second user receive the entire data-array, or just the changes (the pushed value)? I'm a little bit worried that the second user will receive the entire data-array, even though it's just a single value that's been pushed to it, and if data contains many values, I fear this will become a bottleneck.

Is this the case? If it is, using another collection for storing the values will solve it, right? Something like this:

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..."
}

Instead of pushing the values into an array in document, insert them into a collection containing documentData. This (I know) won't have the downside I fear the first solution has (but I rather use the first solution if it doesn't have the downside).

Peppe L-G
  • 7,351
  • 2
  • 25
  • 50
  • 1
    You can double check exactly what comes down wire by following [these instructions](http://stackoverflow.com/questions/8952773/chrome-web-inspector-web-socket-debugging) to view frames in the websocket connection. – user728291 Aug 06 '13 at 12:02

2 Answers2

1

As per https://github.com/meteor/meteor/blob/master/packages/livedata/DDP.md

  • changed (server -> client):
    • collection: string (collection name)
    • id: string (document ID)
    • fields: optional object with EJSON values
    • cleared: optional array of strings (field names to delete)

Users will receive the new array. To only send "diffs," use a collection of {userId: userId, value: value} documents.

DoctorPangloss
  • 2,994
  • 1
  • 18
  • 22
0

I inspected what was sent as commented by user728291, and it seems like the entire array-field is sent, and not just the pushed value. I don't know if this always is the case (I just tested with an array containing few and small values; if it contains many or big values Meteor maybe try to do some optimization I couldn't see in my tiny test), but I'll go with the solution using another collection instead of the array-field.

Peppe L-G
  • 7,351
  • 2
  • 25
  • 50