为什么mongo聚合在流星中不起作用

时间:2015-07-24 21:44:53

标签: meteor

流星newb在这里。我对Meteor的反应感到困惑。我可以从Mongo控制台更新集合,它会立即更新UI。但不是mongo聚合?

我正在使用meteorhacks:聚合以获得在流星中加载的mongo的aggregate()。

聚合效果很好。我可以在mongo控制台中立即看到数据更新。但是,如果我将其暴露给UI,即使在客户端刷新时也没有更新。

db.collection:

{a:1,b:2}
{a:1,b:2}

代码:

inputCollection = new Meteor.Collection('input_collection')
outputCollection = new Meteor.Collection('output_collection')

Meteor.methods({
    pleaseAggregate: function() {
      inputCollection.aggregate([{
        $group : {
            _id : "$a",
            count: { $sum: 1} //should return 2 with the sample data above
        }
      },
      {$out : "output_collection"}
       ]);
    }
});

HTML

<p>Aggregates: {{agg.count}}</p>

Client.js

Template.debug.helpers({
 agg: function() {
    return outputCollection.find().fetch()[0]
  }
});

BTW它正在发布,我安装了'不安全'。

我猜错了流星的东西。它是什么?

2 个答案:

答案 0 :(得分:0)

到目前为止,一切都表明了流星1.1.0.2的错误。 使用来自Mongo {$ 1}的$ out似乎是服务器端的问题。

对于任何寻求解决方案的人来说,有可能获得如下反应性更新:

namespace Extensions{
public static class DateExtensions
{
    public static string GetDifferenceTillNow(this DateTimeOffset? datetimeoffset) {
        DateTimeOffset? creationTime = datetimeoffset;
        DateTimeOffset rightnow = DateTimeOffset.Now;
        DateTimeOffset somewhen = creationTime ?? rightnow;
        TimeSpan difference = rightnow.Subtract(somewhen);
        return difference.Days.ToString() +" days & " +  difference.Hours.ToString() + " hours ago";
    }
  }
}

答案 1 :(得分:0)

被搜索引擎带到这里,不知道是否有帮助,但我也经历过Meteor中的非反应性聚合。我使用了a library for reactive publications