错误:已定义名为“/ users / insert”的方法

时间:2015-05-25 09:50:45

标签: mongodb meteor

我刚刚安装了account-google和accounts-ui软件包,我收到了错误消息:

W20150525-10:41:42.384(1)? (STDERR)           
W20150525-10:41:42.384(1)? (STDERR) /home/andy/.meteor/packages/meteor-tool/.1.1.3.4sddkj++os.linux.x86_64+web.browser+web.cordova/mt-os.linux.x86_64/dev_bundle/server-lib/node_modules/fibers/future.js:245
W20150525-10:41:42.384(1)? (STDERR)                         throw(ex);
W20150525-10:41:42.384(1)? (STDERR)                               ^
W20150525-10:41:42.449(1)? (STDERR) Error: A method named '/users/insert' is already defined
W20150525-10:41:42.449(1)? (STDERR)     at packages/ddp/livedata_server.js:1461:1
W20150525-10:41:42.449(1)? (STDERR)     at Function._.each._.forEach (packages/underscore/underscore.js:113:1)
W20150525-10:41:42.449(1)? (STDERR)     at [object Object]._.extend.methods (packages/ddp/livedata_server.js:1459:1)
W20150525-10:41:42.449(1)? (STDERR)     at [object Object].Mongo.Collection._defineMutationMethods (packages/mongo/collection.js:904:1)
W20150525-10:41:42.449(1)? (STDERR)     at new Mongo.Collection (packages/mongo/collection.js:209:1)
W20150525-10:41:42.449(1)? (STDERR)     at app/meteor.js:1:44
W20150525-10:41:42.449(1)? (STDERR)     at app/meteor.js:16:3
W20150525-10:41:42.450(1)? (STDERR)     at /home/andy/dev/meteor/.meteor/local/build/programs/server/boot.js:222:10
W20150525-10:41:42.450(1)? (STDERR)     at Array.forEach (native)
W20150525-10:41:42.450(1)? (STDERR)     at Function._.each._.forEach (/home/andy/.meteor/packages/meteor-tool/.1.1.3.4sddkj++os.linux.x86_64+web.browser+web.cordova/mt-os.linux.x86_64/dev_bundle/server-lib/node_modules/underscore/underscore.js:79:11)
=> Exited with code: 8

我的代码目前非常简单(对此非常新!)。这是meteor.html

<head>
    <title>Hubbub</title>
</head>

<body style="padding-top: 100px;">
    <div class="container">
        <div class="row">
            <div class="col-xs-12">
                {{> loginButtons}}
                {{> main }}
            </div>
        </div>
    </div>
</body>

<template name="main">

<table class="table table-bordered table-striped table-hover">
    <thead>
        <tr>
            <th>id</th>
            <th>name</th>
            <th>age</th>
            <th>date</th>
        </tr>
    </thead>
    <tbody>
        {{#each users}}
        <tr>
            <td>{{_id}}</td>
            <td>{{name}}</td>
            <td>{{age}}</td>
            <td>{{date}}</td>
        </tr>
        {{/each}}
    </tbody>
</table>


</template>

meteor.js

Users = new Mongo.Collection('users');

if (Meteor.isClient) {

  Template.main.helpers({

    users: function() {
      return Users.find();
    },
    date: function(){
      return moment(this.date).fromNow();
    }

  });
}

我在这里做错了什么?

1 个答案:

答案 0 :(得分:13)

也许您的代码与Meteor默认users集合发生冲突。

您不需要定义Mongo.Collection来处理您的应用用户,Meteor附带了自己的名为Meteor.users的烘焙集合,请改用它,或者将您的集合重命名为其他内容。