So in a situation where you only need a single document, say a post, how do you send just that document down?
Returning document.findOne(documentToFindID)
in a publish call throws an error concerning requiring a cursor be sent.
I’ve thought of different ways for handling this but they all seem…I dunno. Not right. Not wrong…but not right.
Thought One:
Since I was planning on using an ID anyways, just publish the cursor with the ID parameter. It’ll only find one document to publish, then on the client call document.findOne()
without an argument. Should only find a single document, the one I wanted.
This brings the risk for accidentally getting the wrong document if something else is published alongside it.
Thought Two:
Use a meteor method and return the value. Simple, sweet, the closest thing to what I want. I get my value from the server to the client, I only get what I want and need for my route/template.
But…if that document is already cached in MiniMongo I made an extra call for no reason. Once might not be a problem, but as a pattern this could get rough. I could store it in local storage or in a new Meteor.Collections(null)
client only collection but I don’t know if that would really help me or not.
Thought Three:
Either add a package like findInSubscription
or wrap my finders in functions with if(Meter.isServer){...
nested within. This seems dirty and I’m worried it will leak code client side. My understanding is that files in a /server/
directory aren’t sent to the client, but I don’t think the meteor-apper-packager-upper thing removes code inside of isServer blocks.
Meteor makes me think of documents like potato chips…I can’t just have one.
Help me rein in my potat…document addiction.