/microscope /client /client/templates /client/stylesheets
/server /public
/lib /lib/collections/ /lib/collections/posts.js
/lib are loaded before anything else, any main.* file is loaded after everything else everything else loads in alphabetical order based on the file name
meteor up: mup.json and settings.json
meteor shell meteor mongo meteor logs APP_NAME
meteor reset
db.posts.find(); Posts.findOne(); Posts.find().count(); Posts.insert({title: 'Post'}); Posts.find().fetch();
meteor remove autopublish
server/publications.js
Meteor.publish('posts', function(){ return Posts.find(); });
Meteor.publish('posts', function(author){ return Posts.find({author: author}); });
client/main.js
Meteor.subscribe('posts');
Meteor.subscribe('posts', 'bob-smith');
Iron-Router:
- Routes
- Paths
- Segments
- Hooks
- Filters
- Layouts
- Controllers
Tracker.autorun();
Reactively run every time reactive variables change, i.e. Session.set('varA', 'value1');
meteor add ian:accounts-ui-bootstrap-3 meteor add accounts-password
Add the following code to configure the accounts UI to use usernames instead of email addresses:
Accounts.ui.config({ passwordSignupFields: 'USERNAME_ONLY' });
Find users
- Meteor.users.findOne();
- Meteor.users.find().count();
- db.users.count();
Imperative way of observing:
Posts.find().observe({
added: function(post){
} ,
changed: function(post){
},
removed: function(post){
}
});
Declarative way
Templates.postsList.helpers({
posts: function(){
return Posts.find();
}
});
<template name="postsList">
<ul>
{{#each posts}}
<li>{{title}}</li>
{{/each}}
</ul>
</template>
Meteor.startup(function(){ Tracker.autorun(function(){ console.log('There are', Posts.find().count(), 'posts'); }); });
// return the _id of the newly created post post._id = Posts.insert({title: 'New Post'});
meteor remove insecure
Posts = new Mongo.Collection('posts');
Posts.allow({
insert: function(userId, doc){
return !! userId;
}
});
Posts.deny({
});
lib/router.js
var requireLogin = function() { if (! Meteor.user()) { this.render('accessDenied'); } else { this.next(); } }
Router.onBeforeAction(requireLogin, {only: 'postSubmit'});
var requireLogin = function() {
if (! Meteor.user()) {
if (Meter.loggingIn()) {
this.render(this.loadingTemplate);
} else {
this.render('accessDenied');
}
} else {
this.next();
}
}
Router.onBeforeAction('dataNotFound', {
only: 'postPage'
});
Router.onBeforeAction(requireLogin, {
only: 'postSubmit'
});
// lib/router.js