What is returned in a collection.find() when no documents are found? In other words, how do I check if result is null, undefined or what ever is the right thing to look for?
You might try
Collection.find().count() === 0
You beat me to it by 10 seconds!
Thanks. However it returns 0 even though I get a list of 3 documents using the same very basic and simple find(). Has something changed in Meteor 1.2 in terms of publish and subscribe? Do I need to “allow” somewhere?
It’s a function I use in onRendered to check if the result is 0 then make an insert.
UPDATE: Putting it in helpers found them. Wasn’t sure of where to put it.
You should check the count on the server side, probably on the publish method and add your record if the count is equal to 0.
Nope, but you probably forgot to wait for the subscription to be ready…