Server Side Code:
if (Meteor.isClient) {
Meteor.subscribe("messages");
Template.hello.greeting = function () {
Messages = new Meteor.Collection("messages");
Stuff = new Meteor.Collection("stuff");
return "Welcome to feelings.";
};
Template.hello.events({
'click input' : function () {
// template data, if any, is available in 'this'
if (typeof console !== 'undefined')
var response = Messages.insert({text: "Hello, world!"});
var messages = Messages.find
console.log("You pressed the button", response, Messages, Stuff);
}
});
}
if (Meteor.isServer) {
Meteor.startup(function () {
// code to run on server at startup
Messages = new Meteor.Collection("messages");
Messages.insert({'text' : 'bla bla bla'});
});
}
Client Side Code
<head>
<title>Test</title>
</head>
<body>
{{> hello}}
</body>
<template name="hello">
<h1>Hello World!</h1>
{{greeting}}
<input type="button" value="Click"/>
</template>
The problem:
When in javascript console I type Messages.insert({'text' : 'test test test'}); or click the button, underneath which a database insertion call is written
I don't see a document inserted in mongo. Going to mongo console and doing show dbs shows messages (empty)
I have a few other questions, I have read through the meteor docs and also googled but I can't seem to find a clear answer to this:
- Why do I need to declare a collection in client as well as server code?
- I'm declaring collections inside Template.hello.greeting, what's the difference if I put it in if(Meteor.isClient) block directly.
- Is any plans of adding some app directory structure in meteor like rails? where models and templates are separate? I'm not talking about express.js
Thanks.