【问题标题】:insert failed: Method in meteor 1.3 and react插入失败:流星 1.3 中的方法并做出反应
【发布时间】:2016-04-22 09:34:25
【问题描述】:

我想通过 react 向 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>
    );
  }
}

【问题讨论】:

  • 集合也需要在服务器上定义。
  • 另外,collection.allow 是一个服务器端函数。
  • @DavidWeldon 谢谢,现在可以工作了。

标签: javascript mongodb meteor reactjs


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2013-09-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-13
    相关资源
    最近更新 更多