Collection update returns the complete document when updating second level key


#1

My collection structure :

[
	{
		_id: id,
		createdAt: date,
		name: string,
		subObject: {
			id: {
				name: string,
				type: string,
				coordinates: [ [] ], // big
			},
			id: {
				name: string,
				…
		}
	},
	{
		_id: id,
		…

When I update my collection that way :

	Collection.update( {
		_id: targetID,
	}, {
		$set: {
			[ `subObjects.${ id }.type` ]: type,
		},
	} );

Meteor send the complete updated object trough the socket.

Why not… except that subObject is a large collection of coordinates arrays. So the socket send me 1 to 5 mo each time I make an update depending of the target. This is not usable.

Is there a way to ask for atomic updates answers ?

in the socket, the request message is :

["{\"msg\":\"method\",\"method\":\"/collection/update\",\"params\":[{\"_id\":\"dJGDKXuJtWDrgDZgn\"},{\"$set\":{\"subObjects.xxx.type\":\"type_name\"}},{}],\"id\":\"3\"}"]

And the answer :

{"msg":"changed","collection":"geometries","id":"dJGDKXuJtWDrgDZgn","fields":{"subObjects":[{"XXX… and soooo much more

When I update a first level key in my collection object it returns only that key. Why not when I update a second level ?

I tried to make subObject an array instead of an object. Does not fix.


#2

This is an implementation feature of the diffing algorithm used:

Changes are propagated at the top level only.


#3

Does that mean that the only solution I have is to put every keys of my sub object at the top level ?


#4

No. It’s just that the entire top level object is marked as changed, even if only the tip of the object is changed.