我想用react将简单的文本插入到mongo数据库中,但是,当我提交表单时,在控制台中打印下面这行:
insert failed: Method '/resolutions/insert' not found
提示:已经安装了autopublish和insecure。我有react 15和meteor 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>
);
}
}
发布于 2016-04-23 03:04:32
一小时前才遇到这个问题。你会想要做'Resolutions._collection.insert‘而不仅仅是'Resolutions.insert’。
https://stackoverflow.com/questions/36790152
复制相似问题