流星500错误
Meteor 500 error
我正在开发一个以 React 作为前端库的 Meteor 应用程序。
目前,我正在尝试将数据插入 Accounts 集合,但我的代码出现 500 错误。不幸的是,控制台错误不是我可以直接使用 Meteor 的经验。
控制台错误:
I20180815-21:04:45.128(2)? Exception while invoking
method'customers.insert' ReferenceError: document is not defined
I20180815-21:04:45.129(2)? at MethodInvocation.customers.insert
(imports/collections/customers.js:13:27)
I20180815-21:04:45.129(2)? at maybeAuditArgumentChecks
(packages/ddp-server/livedata_server.js:1767:12)
I20180815-21:04:45.129(2)? at DDP._CurrentMethodInvocation.withValue
(packages/ddp-server/livedata_server.js:719:19)
I20180815-21:04:45.129(2)? at
Meteor.EnvironmentVariable.EVp.withValue (packages/meteor.js:1304:12)
I20180815-21:04:45.129(2)? at DDPServer._CurrentWriteFence.withValue
(packages/ddp-server/livedata_server.js:717:46)
I20180815-21:04:45.130(2)? at
Meteor.EnvironmentVariable.EVp.withValue (packages/meteor.js:1304:12)
I20180815-21:04:45.130(2)? at Promise (packages/ddp-server
/livedata_server.js:715:46)
I20180815-21:04:45.130(2)? at new Promise (<anonymous>)
I20180815-21:04:45.130(2)? at Session.method (packages/ddp-server.
/livedata_server.js:689:23)
I20180815-21:04:45.130(2)? at packages/ddp-server
/livedata_server.js:559:43
我想这可能与进口有关,但我想不通。
我的其余代码:
customer.js
import { Mongo } from 'meteor/mongo';
Meteor.methods({
'customers.insert': function() {
console.log('test');
},
'customers.remove': function(customer) {
return Customers.remove(customer);
}
});
export const Customers = new Mongo.Collection('customers');
customer_create.js
import React, { Component } from 'react';
class CustomersCreate extends Component {
onFormSubmit(event) {
event.preventDefault();
Meteor.call('customers.insert');
}
render() {
return (
<div>
<form onSubmit={this.onFormSubmit.bind(this)}>
<fieldset>
<label htmlFor="contactemail">E-mailadres contactpersoon</label>
<input id="contactemail" name="contactemail" type="text" />
</fieldset>
<fieldset>
<label htmlFor="password">Wachtwoord</label>
<input id="password" name="password" type="text" />
</fieldset>
<fieldset>
<label htmlFor="password">Wachtwoord bevestigen</label>
<input id="confirmpassword" name="confirmpassword" type="text" />
</fieldset>
<fieldset>
<button className="submit-button">Toevoegen</button>
</fieldset>
</form>
</div>
);
}
}
export default CustomersCreate;
最后是我的订阅:
import { Meteor } from 'meteor/meteor';
import { RegistrationCards } from '../imports/collections/registrationcards';
import { Customers } from '../imports/collections/customers';
Meteor.startup(() => {
Meteor.publish('registrationcards', function() {
return RegistrationCards.find({});
});
Meteor.publish('customers', function() {
return Customers.find({});
});
});
补充:当我试图解决这个问题时,我还注意到我得到以下异常:
Exception while simulating the effect of invoking 'customers.insert' TypeError: "event is undefined"
@edit:修复了最后的问题。打了个小错
控制台上的错误是一个引用错误,指出该文档未定义。您如何插入新客户?您没有从代码中指定它。理想的方法是使用表单字段中的值创建一个客户对象,并在调用 'customer.insert' 方法时将客户对象传递给它。
const 客户 = {
姓名:
}
//调用传入对象的方法
Meteor.call('customer.insert', 顾客)
在服务器端的 'customer.insert' 方法中,您在客户文档中进行了插入。
Customer.insert(客户)
我正在开发一个以 React 作为前端库的 Meteor 应用程序。 目前,我正在尝试将数据插入 Accounts 集合,但我的代码出现 500 错误。不幸的是,控制台错误不是我可以直接使用 Meteor 的经验。
控制台错误:
I20180815-21:04:45.128(2)? Exception while invoking
method'customers.insert' ReferenceError: document is not defined
I20180815-21:04:45.129(2)? at MethodInvocation.customers.insert
(imports/collections/customers.js:13:27)
I20180815-21:04:45.129(2)? at maybeAuditArgumentChecks
(packages/ddp-server/livedata_server.js:1767:12)
I20180815-21:04:45.129(2)? at DDP._CurrentMethodInvocation.withValue
(packages/ddp-server/livedata_server.js:719:19)
I20180815-21:04:45.129(2)? at
Meteor.EnvironmentVariable.EVp.withValue (packages/meteor.js:1304:12)
I20180815-21:04:45.129(2)? at DDPServer._CurrentWriteFence.withValue
(packages/ddp-server/livedata_server.js:717:46)
I20180815-21:04:45.130(2)? at
Meteor.EnvironmentVariable.EVp.withValue (packages/meteor.js:1304:12)
I20180815-21:04:45.130(2)? at Promise (packages/ddp-server
/livedata_server.js:715:46)
I20180815-21:04:45.130(2)? at new Promise (<anonymous>)
I20180815-21:04:45.130(2)? at Session.method (packages/ddp-server.
/livedata_server.js:689:23)
I20180815-21:04:45.130(2)? at packages/ddp-server
/livedata_server.js:559:43
我想这可能与进口有关,但我想不通。
我的其余代码:
customer.js
import { Mongo } from 'meteor/mongo';
Meteor.methods({
'customers.insert': function() {
console.log('test');
},
'customers.remove': function(customer) {
return Customers.remove(customer);
}
});
export const Customers = new Mongo.Collection('customers');
customer_create.js
import React, { Component } from 'react';
class CustomersCreate extends Component {
onFormSubmit(event) {
event.preventDefault();
Meteor.call('customers.insert');
}
render() {
return (
<div>
<form onSubmit={this.onFormSubmit.bind(this)}>
<fieldset>
<label htmlFor="contactemail">E-mailadres contactpersoon</label>
<input id="contactemail" name="contactemail" type="text" />
</fieldset>
<fieldset>
<label htmlFor="password">Wachtwoord</label>
<input id="password" name="password" type="text" />
</fieldset>
<fieldset>
<label htmlFor="password">Wachtwoord bevestigen</label>
<input id="confirmpassword" name="confirmpassword" type="text" />
</fieldset>
<fieldset>
<button className="submit-button">Toevoegen</button>
</fieldset>
</form>
</div>
);
}
}
export default CustomersCreate;
最后是我的订阅:
import { Meteor } from 'meteor/meteor';
import { RegistrationCards } from '../imports/collections/registrationcards';
import { Customers } from '../imports/collections/customers';
Meteor.startup(() => {
Meteor.publish('registrationcards', function() {
return RegistrationCards.find({});
});
Meteor.publish('customers', function() {
return Customers.find({});
});
});
补充:当我试图解决这个问题时,我还注意到我得到以下异常:
Exception while simulating the effect of invoking 'customers.insert' TypeError: "event is undefined"
@edit:修复了最后的问题。打了个小错
控制台上的错误是一个引用错误,指出该文档未定义。您如何插入新客户?您没有从代码中指定它。理想的方法是使用表单字段中的值创建一个客户对象,并在调用 'customer.insert' 方法时将客户对象传递给它。 const 客户 = { 姓名: } //调用传入对象的方法 Meteor.call('customer.insert', 顾客) 在服务器端的 'customer.insert' 方法中,您在客户文档中进行了插入。 Customer.insert(客户)