meteor - 插入失败 : Method not found

标签 meteor

我的 Meteor 的 JS 文件有问题。当我尝试将任何数据插入数据库并反射(reflect)在图表上时,我收到此错误“插入失败:找不到方法”。我试过直接从数据库中获取数据,但也没有用…… 提前谢谢。

LinePeople = new Mongo.Collection("LinePeople");
function getRandomInt(min, max) {
    return Math.floor(Math.random() * (max - min + 1)) + min;
}

if (Meteor.isClient) {
    console.log("in LIne Client");

    //LinePeople = new Mongo.Collection(null);

    Template.linenvd3.rendered = function() {
        var chart = nv.models.lineChart()
            .margin({left: 80})  //Adjust chart margins to give the x-axis some breathing room.
            .useInteractiveGuideline(true)  //We want nice looking tooltips and a guideline!
            .transitionDuration(350)  //how fast do you want the lines to transition?
            .showLegend(true)       //Show the legend, allowing users to turn on/off line series.
            .showYAxis(true)        //Show the y-axis
            .showXAxis(true)        //Show the x-axis
        ;

        nv.addGraph(function() {
            chart.xAxis.axisLabel('Person number').tickFormat(d3.format('d'));
            chart.yAxis.axisLabel('Age (years)').tickFormat(d3.format('d'));
            d3.select('#lineChart svg').datum(
                [{ values: LinePeople.find().fetch(), key: 'Age' }]
            ).call(chart);
            nv.utils.windowResize(function() { chart.update() });
            return chart;
        });

        Deps.autorun(function () {
            d3.select('#lineChart svg').datum(
                [{ values: LinePeople.find().fetch(), key: 'Age' }]
            ).call(chart);
            chart.update();
        });
    };

    Template.linenvd3.events({
        'click #addDataButton': function() {

            console.log(" in line addButton");

            var age = getRandomInt(13, 89);
            var lastPerson = LinePeople.findOne({}, {fields:{x:1},sort:{x:-1},limit:1,reactive:false});
            if (lastPerson) {
                console.log(" in lastPerson.. if block");
                LinePeople.insert({x:(lastPerson.x + 1), y:age});
            } else {
                console.log(" in lastPerson.. else block");
                LinePeople.insert({x:1, y:age});
            }
        },
        'click #removeDataButton': function() {
            console.log(" in line removeButton");
            var lastPerson = LinePeople.findOne({}, {fields:{x:1},sort:{x:-1},limit:1,reactive:false});
            if (lastPerson) {
                LinePeople.remove(lastPerson._id);
            }
        }
    });
}

if (Meteor.isServer) {
    console.log("in line Server");

}

最佳答案

在关注 meteor .js 官方网站上的入门教程时,我在打开自动发布时遇到了同样的问题。

原来问题是我在 imports/ 文件夹中创建了我的 Tasks 集合。因此它没有被隐式导入到服务器上。

我必须在服务器上显式导入它才能解决问题。

server/main.js

import { Meteor } from 'meteor/meteor';
import '../imports/api/tasks.js';

Meteor.startup(() => {  
  // code to run on server at startup
});

如您所见,我的代码没有使用导入,但无论如何都是必需的。

关于 meteor - 插入失败 : Method not found,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28223725/

相关文章:

javascript - meteor ,铁 :Router Passing Multiple Properties on Router. 去

cordova - 如何通过 NGINX + SSL 配置 Meteor 构建并运行 Cordova 构建?

javascript - 打印出哈希值?

javascript - i18n 用于 react 组件的数组元素

arrays - Meteor、MongoDB通过订阅获取数组的一部分

javascript - 为 meteor 中的自定义路由设置重置密码 token

javascript - 通过同步调用检查用户是否存在

css - 如何测试 LESS 文件是否正在编译?

css - Meteor.js 上的 Stylus 库

javascript - meteor .js : I want to play a sound when someone recieves a message in a simple chat app