Discover Meteor: return _id or not?


Just a basic question on the Discover Meteor tutorial. I’ve worked through the Microscope exercise but now trying to understand how I replicate in my own project.

I’m comparing the postInsert method…

    var postId = Posts.insert(post);
    return {
        _id: postId

…with the two ways we insert Posts in Fixtures file.


    var telescopeId = Posts.insert({...});
    postId: telescopeId,

Option #2


These are all slightly different but all seem to work the same way. So my question is, what is the purpose of :

return {
    _id: postId

…in the method? The book says “returning the resulting _id to the client (in other words, the original caller of this method) in a JavaScript object”. But if it isn’t necessary in Fixtures and I can still access those documents, why is it necessary? Specifically, is excluding this code the reason I’m having trouble returning the _id from documents when querying on other attributes?

Complete beginner to all programming so forgive the elementary question. Thanks for any help.



If you are writing method, it is nice to return something. When you are calling it usually from client, there is callback argument which gets this result and error code. It is nice to have something returned.

And it should not affect any find operation results above collections.

I did not read the book, so dont know all these case uses u refer to.


Thank you very much. All good info.