Reputation: 1623
I defined the collection in lib/collection.js
var Tags = new Meteor.Collection("Tags");
Then trying to initialize it in server/main.js:
Tags.insert({name: tag["tag"], default_show: true});
Got error: W20141028-01:26:53.647(11)? (STDERR) ReferenceError: Tags is not defined W20141028-01:26:53.648(11)? (STDERR) at app/server/main.js:43:18
I cannot figure out why I got error here? Anyone could give me some hints?
Full source code:
server/main.js
Meteor.startup(function() {
var tagsJson = JSON.parse(Assets.getText("tags.json"));
var tagsMapJson = JSON.parse(Assets.getText("tags_map.json"));
tagsJson["lines"].map(function(line) {
line["tags"].map(function(tag){
if (!Tags.findOne({name: tag["tag"]})) {
Tags.insert({name: tag["tag"], default_show: true});
}
tagsMapJson[tag["tag"]].map(function(web) {
if (!Webs.findOne({url: web["url"]})) {
Webs.insert({url: web["url"], name: web["name"], brief: web["brief"]});
}
if (!TagWebs.findOne({tag: tag["tag"], url: web["url"]})) {
TagWebs.insert({tag: tag["tag"], url: web["url"]});
}
});
});
});
});
lib/collections.js
var Tags = new Meteor.Collection("Tags");
var Webs = new Meteor.Collection("Webs");
var TagWebs = new Meteor.Collection("TagWebs");
Upvotes: 0
Views: 121
Reputation: 1881
I think you should erase "var" so collection is seen to whole project
Upvotes: 1