【问题标题】:Method runs fine on local, will not run when deployed (on meteor.com)方法在本地运行良好,部署时不会运行(在meteor.com上)
【发布时间】:2015-10-02 09:44:34
【问题描述】:

我有一个在本地完美运行的 Meteor 应用程序,但是当我部署到 meteor.com 时,一种方法将无法运行。所有其他方法都运行良好。

这是相关代码:

客户端:按钮单击以将公司添加到数组

Template.ValuationTableComps.events ({
    'submit form': function(e) {
        e.preventDefault();
        var valuationId = this._id;
        var selection = {
        valuationSelections: $(e.target).find('[name=selectionComp]').val()};
        Valuations.update(valuationId, {$addToSet: selection}, function () {});
    }
});

客户端:按钮单击以根据上面的选择重新运行数组

Template.ValuationCalc.events({
    'click #agg': function(e) {
        e.preventDefault();
        var valuationId = this._id;
        var valuationSelections = this.valuationSelections;
        Meteor.call('valuationAggregate', valuationId, valuationSelections, function (error, result) {});
    }
});

Lib:运行聚合并将结果插入新集合的方法

Meteor.methods({
    valuationAggregate: function(valuationId, valuationSelections) {
        if (Meteor.isServer) {
            check(valuationId, String);
            check(valuationSelections, Array);
            var pipelineSelections = [
            //build pipeline//
            ];
            var results = Companies.aggregate(pipelineSelections);
            results.forEach(function(valuationResults) {
                ValuationResults.update({valuationId: valuationId}, valuationResults, {upsert: true});
            });
        }
    }});

在本地运行时一切正常。我可以在客户端和服务器上 console.log valuationIdvaluationSelectionsValuationResults.find({valuationId:valuationId}).fetch() 并且都返回正确的结果。

但是,当我部署到 meteor.com 时,该方法不会运行。在我的浏览器控制台中,我看到了valuationIdvaluationSelections。但是,ValuationResults 查询返回 [ ]

我在 ValuationResults 中有可以在浏览器控制台中看到的虚拟数据,因此集合很好。但我不明白为什么该方法可以在本地工作,但不能在部署时工作。这是唯一不起作用的,其他都很好。谢谢。

【问题讨论】:

标签: javascript meteor web-deployment


【解决方案1】:

已解决:

我能够运行 meteor logs myApp 并看到错误 MongoError: exception: invalid operator '$literal'。我的$project 阶段包括valuationId: {$literal: valuationId} 以向新文档添加新字段。我不知道为什么会抛出错误,但似乎存在一个已知的 mongodb 问题:https://jira.mongodb.org/browse/RUBY-668

我将$literal 从我的管道中取出,只是更新了现有的估值文件。现在在本地和部署时都可以正常工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-11-28
    • 1970-01-01
    • 1970-01-01
    • 2017-06-16
    • 1970-01-01
    • 2013-02-12
    • 1970-01-01
    相关资源
    最近更新 更多