我正在努力让我的项目与Routing一起工作,我想有些事情确实是错误的。
目前正在记录异常
Error: There is already a collection named "person"
at new Mongo.Collection (packages/mongo/collection.js:240:15)
at meteorInstall.collections.persons.js (collections/persons.js:2:23)
at fileEvaluate (packages/modules-runtime.js:197:9)
at require (packages/modules-runtime.js:120:16)
at /home/usr/Dev/simple-todos/.meteor/local/build/programs/server/app/app.js:198:1
at /home/usr/Dev/simple-todos/.meteor/local/build/programs/server/boot.js:303:34
at Array.forEach (native)
at Function._.each._.forEach (/home/usr/.meteor/packages/meteor-tool/.1.4.3_2.7s3fq6++os.linux.x86_64+web.browser+web.cordova/mt-os.linux.x86_64/dev_bundle/server-lib/node_modules/underscore/underscore.js:79:11)
at /home/usr/Dev/simple-todos/.meteor/local/build/programs/server/boot.js:128:5
at /home/usr/Dev/simple-todos/.meteor/local/build/programs/server/boot.js:352:5
Exited with code: 1
Your application is crashing. Waiting for file change.
以下是我的代码:
routes.js (在lib文件夹中加载,以便首先加载)
Router.configure({
layoutTemplate: 'layout'
});
Router.route('/', function () {
this.render('personTemplate');
});
主要布局模板(作为整个应用程序的容器)+用于指导主模板上路径的产量容器。
<template name="layout">
<nav class="deep-orange lighen-4" role="navigation">
<div class="nav-wrapper container left">
<ul class="right">
<li><a href="test.html">test</a></li>
<li><a href="/about">about</a></li>
{{> loginButtons}}
<!-- <i class="material-icons" style="font-size:30px;color:grey">person</i> -->
</ul>
<a href="#" class="brand-logo left ">SiteName</a>
</div>
</nav>
{{> yield}}
</template>
person.js(集合定义文件 - 也位于首先加载的lib文件夹中)
import {mongo} from 'meteor/mongo';
export const Person = new Mongo.Collection('person');
personTemplate 定义
<template name="personTemplate">
{{#each person}}
{{> todosTest}}
{{/each}}
</template>
<template name="todosTest">
<ul>{{name}}</ul>
</template>
人员帮助 - 将执行对人员集合的查找
import { Template } from 'meteor/templating';
import { Person } from '../../lib/collections/persons.js';
import { ReactiveVar } from 'meteor/reactive-var';
import '../templates/personTemplate.html';
Template.personTemplate.helpers({
person(){
var aPerson = Person.find({});
// check for existence before returning
return aPerson && aPerson.name
}
});
最后我的 main.js 文件在服务器上加载集合:
import { Meteor } from 'meteor/meteor';
import '../lib/collections/persons.js';
在图形下方显示文件夹布局:
答案 0 :(得分:1)
您正在定义集合&#39; Person&#39;两次在两个不同的文件夹中使用相同的文件。