Meteor:使用Meteor.methods()的内部服务器错误[500]

时间:2016-05-25 20:25:11

标签: javascript mongodb meteor aggregation-framework

我有收集"菜单"结构:

f = plt.figure(figsize=(5,5))
plt.subplot(2, 2, 1)
# this "A" is clipped in the plot
plt.annotate("A",
             xy = (-0.25, 1.1),
             xytext = (-0.25, 1.1),
             xycoords = 'axes fraction',
             textcoords = 'axes fraction',
             fontsize=30)
plt.subplot(2, 2, 2)
plt.subplot(2, 2, 3)
plt.subplot(2, 2, 4)
plt.tight_layout()
plt.show()

我想只向用户显示"部分"不重复 为此我用过 Menu.aggregate([{$组:{_ ID:" $部分"}}]) 但它不起作用 我怎样才能做到这一点?可能是使用不同的方法?

服务器端:

figsize

导致服务器:[' vine','啤酒''牛奶' ]

客户方:

{
"_id" : "vJQr7EuieDHMuX2nx" "section" : "vine" "price" : "200" "category" : "bar"
"_id" : "vJQr7EuieDHMuX4rf" "section" : "beer" "price" : "200" "category" : "kitchen"
"_id" : "vJQr7EuieDHMuX5tg" "section" : "milk" "price" : "200" "category" : "kbar"
"_id" : "vJQr7EuieDHMuX4sc" "section" : "beer" "price" : "200" "category" : "kitchen"
"_id" : "vJQr7EuieDHMuX2xs" "section" : "vine" "price" : "200" "category" : "bar"
}

我不知道在哪里可以找到解决方案

2 个答案:

答案 0 :(得分:0)

您可能需要高级出版物。在模板代码中,添加命名集合(仅在客户端上)。然后,您可以创建一个帮助程序来获取数据并订阅发布。

const Sections = new Mongo.Collection('sections');
Template.Menu.onCreated(function () {
  this.subscribe('sections')
})
Template.Menu.helpers({
  sections() {
    return Sections.find();
  }
});

然后,创建一个写入此内容的发布。

Meteor.publish('sections', function () {
  const handle = Menu.find({}, {
    fields: {
      _id: 0
      section: 1
   }
  }).observe({
    added: doc => this.added('sections', doc.section, doc),
    changed: doc => this.changed('sections', doc.section, doc),
    removed: doc => this.removed('sections', doc.section, doc)
  });
  this.ready();
  this.onStop(() => handle.stop())
})

答案 1 :(得分:0)

Meteor使用MiniMongo - 它自己的nodejs MongoDB驱动程序的包装器。

默认情况下,collecions没有方法aggregate。您可以在一些软件包中找到它,例如monbro:mongodb-mapreduce-aggregation

或者(更好的imo)你可以使用Meteor rawCollection方法访问原始集合:

Menu.rawCollection().aggregate(pipeline, function(err, res) {
    //do stuff here
})