To answer your second question, it is best to use the Meteor methods in the server directory. Meteor uses these reserved directory names to give you control over resources that are served by a client, server, or both. You do not have to have them in the same file or directory as your Mongo collections, since all your collections can be accessed both on the client and on the server. This is usually considered best practice, especially if you use frameworks such as angular-meteor, which rely on Collection definitions available on the client so that filters can be passed to them. You can protect and change permissions for these Collections by using collection.allow()/deny()
So, if you saved all your collections in the collections/ directory, they can be defined as follows:
Workouts = new Mongo.Collection('workouts');
will be the contents of collections/workouts.js
Then, in your server/ directory at the same level as your collections/ , you can put all your methods in a file at that level or deeper in the tree, for example, in the server/methods/ directory. Then you can put your methods in workouts.js in this directory if you want.
Meteor.methods({ workoutInsert: function () { var user = Meteor.user(); check(user._id, String); var workout = { completed: false, createdAt: new Date(), userId: user._id }; var workoutId = Workouts.insert(workout); return { _id: workoutId }; } });
source share