2016-04-22 49 views
1

我想插入简单的文字来蒙戈数据库反应,但是,当我提交表单打印此行控制台:插入失败:法流星1.3和反应

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> 
 
    ); 
 
    } 
 
}

+0

集合还需要在服务器上定义。 –

+0

另外,'collection.allow'是一个服务器端函数。 – aedm

+0

@DavidWeldon谢谢,现在工作。 – Sajad

回答

1

恰好碰到了这个问题一个小时前。你将要做'Resolutions._collection.insert'而不是'Resolutions.insert'。