Hello everyone!
I study meteor with LevelUp Tuts from youtube and got some problems from start.
This is my code:
client/main.html
<body>
<ul>
{{#each resolutions}}
{{> resolution}}
{{/each}}
</ul>
</body>
<template name="resolution">
<li>
{{title}}
</li>
</template>
client/main.js
import { Mongo } from 'meteor/mongo';
const Resolutions = new Mongo.Collection('resolutions');
Template.body.helpers ({
resolutions() {
console.log(Resolutions.find({}).count()); // returns 0
return Resolutions.find({});
},
});
I inserted some data via meteor mongo console:
db.Resolutions.insert({title:"test",createdAt:new Date()})
and with low-case āresolutionā
db.resolutions.insert({title:"test",createdAt:new Date()})
But at front-end I see no output data and no console errors also.
Meteor version 1.3
What is wrong with my code?
Can anyone help please?
Did you publish and subscribe to the collection? Use msavin:mongol to check if the collection is subscribed to on client.
No, I just follow the tutorial.
Iāll try msavin:mongol.
thanks!
I have an idea!
I use cloud9 platform as IDE and hosting 2-in-1.
And I noticed this:
mongo server parameters:
MongoDB shell version: 2.6.7
connecting to: 127.0.0.1:8081/meteor
The same time meteor itself run at
App running at: http://0.0.0.0:8080/
Different IP and ports!
May be the problem because of that??
P.S. but I made āto-doā app from official meteor tutorial and it worked ok at the same environmentā¦
Is that all your code?
As it stands, you are not sharing the collection between client and server, so itās currently a client-only collection.
If you intend using the new import
syntax, then I suggest you read the introductory Meteor tutorial. However, you could do the following, which should get you up and running (typos notwithstanding!):
Create an imports/api
folder.
In imports/api/Resolutions.js
import { Mongo } from 'meteor/mongo';
export const Resolutions = new Mongo.Collection('resolutions');
and replace const Resolutions = new Mongo.Collection('resolutions');
in your client/main.js
with import { Resolutions } from '/imports/api/Resolutions.js';
.
In server/main.js
import { Resolutions } from '/imports/api/Resolutions.js';
or
import '/imports/api/Resolutions.js';
if you donāt need access to the Resolutions
collection in server/main.js
.
BTW, in the meteor mongo
shell, you should use db.resolutions
.
1 Like
@robfallows , it works!
Many thanks for your help!
The key point was to use import in server/main.js
1 Like