meteor-feature-requests
meteor-feature-requests copied to clipboard
Support merging subfields in DDP (or separate multiple subscriptions instead of merging)
Migrated from: meteor/meteor#3764
It's not possible to subscribe to a publication multiple times to get different subfields.
For example, let say we have a collection where each document have a data
attribute, inside this data
attribute there can be anything (temperature, speed, etc), so each document can be different and the use of a data attribute allows to put anything inside without taking the risk to override "meta attributes".
So the simple publication below :
Meteor.publish("data", objectId, fields, () => {
return Data.find({objectId}, {fields, sort: {createdAt: -1}});
});
Would return this kind of data :
[
{
"objectId": "P0I6JsjAfXepz5",
"createdAt": 1497036846026,
"data": {
"temp": 78.9,
"tempUnit": "C"
},
{
"objectId": "uKl9pR5m73za",
"createdAt": 1497036848287,
"data": {
"humidity": 62.3,
"humidityUnit": "%"
}
]
Now imagine that we have a dashboard with several monitors that should return specific data for different objects, we need to subscribe multiple times to the same subscription with different params :
Meteor.subscribe("data", "uKl9pR5m73za", {objectId: 1, createdAt: 1, "data.humidity": 1, "data.humidityUnit": 1});
Meteor.subscribe("data", "P0I6JsjAfXepz5", {objectId: 1, createdAt: 1, "data.temp": 1, "data.tempUnit": 1});
This is a simple example where objects are very small but in real they contains more than 2 values in the data
attribute, so we only need to get the needed ones, thus filling the fields
param of the data
publication to optimize the query.
The problem is that it only works for the first subscription, the following subscriptions do not return the other subfields of the document, forcing us to get the full content data
even if we don't need it...