Reputation: 412
If I use Meteor.publish to push documents to a client side collection (like in the "messages-count" example), then what happens when I inser/update/remove on that client side collection (called "messages-count" in the example in the docs)? Does anything reach the server, considering the "messages-count" collection does not even exist on the server? How do we propogate the document changes to the server in that case?
Note: i've seen @debergalis 's stellar answer where he explains this example in detail (here: https://stackoverflow.com/a/10566873/694222 ), and that makes perfect sense. But it doesn't touch upon what happens when the client side collection ("counts", in his example) is called to insert/update docs.
UPDATE:
So I tried it out myself, and this is what happens: If I have a client side collection called Counts (that is populated using Meteor.publish), then Counts.find works fine, but Counts.insert simply doesn't work, saying no relevant Meteor.method found, which is fine.
But now I have a new problem. If my subscribed client side collection has the same name as the published server side collection (i have already removed the autopublish meteor package), then doing an insert client side does propagate to the server side and adds the document to server-side mongo. This is obviously not acceptable..
So basically, a client side collection with the same name (what you pass into new Meteor.Collection) can successfully update the server-side collection with the same name, even with the autopublish package turned off. Is this a bug?
Upvotes: 3
Views: 830
Reputation: 11
If I use Meteor.publish to push documents to a client side collection (like in the "messages-count" example), then what happens when I inser/update/remove on that client side collection (called "messages-count" in the example in the docs)?
The "messages-count" example in the API docs is using a "named" collection. The collection name is "messages-count". All named collections exist server side. When you insert/update/delete client side the changes automatically propagate to the server collection.
Here's an excerpt from the API docs:
If you pass a name when you create the collection, then you are declaring a persistent collection — one that is stored on the server and seen by all users. Client code and server code can both access the same collection using the same API.
Next question:
Does anything reach the server, considering the "messages-count" collection does not even exist on the server?
The collection does exist on the server (see above), so yes all inserts/updates/deletes on the client side collection will propagate to the server.
How do we propogate the document changes to the server in that case?
If you do have a client side only collection (eg., a collection created with a null name), then what would you have to propagate to the server? If you want your changes to propagate then use a named collection.
Upvotes: 0
Reputation: 12348
messages-count
is not a collection, it's record set with a single record containing a single attribute.
You pass it a room ID, it returns you its count; you can't do anything more with that record set...
Upvotes: 0