Blog Lab

Meteor: Publish Empty Collection for Inserting Only

I’m writing a meteor app and ran into a problem where I only need a collection reference to be able to insert new documents into it. I don’t need to read any data from the collection. I think by publishing an empty collection would save the effort in synchronizing data between the server and the client which would make the app more efficient. I couldn’t find anything helpful by Googling so I came up with something myself and so far it seems to be working just fine.

Here’s how:

(Code clip removed)

I’m simply adding a filter that’s always going to get me nothing. I guess I would never have attribute undefined defined on any documents, so that would work for me.

Hope you find this helpful. šŸ™‚

Actually you don’t even need a subscription in order to insert, as long as the server side has the same collection defined as the client side. Didn’t know that.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.