流星 - Sub的例外。 Publish Function返回了一个非游标数组

时间:2016-08-11 22:26:44

标签: javascript mongodb meteor

我试图发布一个集合,但我的控制台说它返回一个数组。

服务器/ publish.js

require "rails_helper"

RSpec.feature "Carpool Invitations", :type => :feature do
  let!(:carpool) { FactoryGirl.create(:carpool)}
  # you could still create a user here if you wanted

  scenario "User sends a new carpool invite" do
    sign_in
    visit new_carpool_invite_path(carpool)
    fill_in "invite[to_user]", :with => "matthewalexander108@gmail.com"
    click_button "Send Invitation"
    expect(page).to have_text("Invitation was successfully sent!")
  end
end

RelypheTopContainer.jsx

HeartCount = new Mongo.Collection('heartcount');

Meteor.publish("currentHeartCount", function() {
    return HeartCount.find().fetch();
});

RelypheTop.jsx

class RelypheTopContainer extends TrackerReact(React.Component) {

  currentHeartCount() {
    return HeartCount.find().fetch();
  }

  componentWillUnmount() {}
  data() {
    const params = this.props.params;
    const id = params.id;

    this.state = {
      subscriptions: {
        relyphe: RelypheSubs.subscribe('oneRelyphe', id),
        heartCount: Meteor.subscribe('currentHeartCount', id)
      }
    };
}

我试图将当前计数放入#output div以显示在所有用户屏幕上。

1 个答案:

答案 0 :(得分:1)

.fetch()将游标转换为数组。使用:

Meteor.publish("currentHeartCount", function() {
    return HeartCount.find();
});