【发布时间】:2016-04-22 09:34:25
【问题描述】:
我想通过 react 向 mongo 数据库插入简单的文本,但是,当我提交表单时,在控制台中打印这一行:
insert failed: Method '/resolutions/insert' not found
提示:autopublish 和 insecure 已安装。我有反应 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