插入失败:流星1.3中的方法并做出反应

时间:2016-04-22 09:34:26

标签: javascript mongodb meteor reactjs

我希望将简单的文本插入到mongo数据库中,但是,当我提交表单时,在控制台中打印此行:

insert failed: Method '/resolutions/insert' not found

提示:autopublishinsecure已安装。我已经做出反应15和流星1.3.1

这是我的代码:

import { Meteor } from 'meteor/meteor';
import React from 'react';
import ReactDOM from 'react-dom';

Resolutions = new Mongo.Collection('resolutions');
Resolutions.allow({
  insert: function(userId,doc) {
    return true;
  }
});

// import './index.html';

export default class App extends React.Component {

  AddResolution(event) {
    let text = this.refs.resolutions.value.trim();
    // Insert into database
    Resolutions.insert({
      text: text,
      complete: false,
      createAt: new Date()
    });
    this.refs.resolutions.value = "";
    event.preventDefault();
  }
  render() {
    return (
      <div>
        <h1>My swsolutions</h1>
        <form className="new-resolution" onSubmit={this.AddResolution.bind(this)}>
          <input type="text" ref="resolutions" placeholder="Finish React Meteor"/>
        </form>
      </div>
    );
  }
}

1 个答案:

答案 0 :(得分:1)

一小时前刚遇到这个问题。你想要做'Resolutions._collection.insert',而不仅仅是'Resolutions.insert'。