我在Meteor中使用Simple Schema,集合挂钩和Autoform包,我试图在更新后的集合钩子中更新我的架构中的Embedded对象。我觉得我可能会做些傻事,但却无法解决这个问题。我在保存时得到了这个例子:Exception while invoking method '/providers/update' Error: 0 must be an integer
我的架构:
Schemas.Providers = new SimpleSchema({
email: {
type: String,
label: 'Email Address',
autoValue: function() {
if (this.isInsert || this.isUpdate) {
return Meteor.user().emails[0].address;
}
},
autoform: {
afFieldInput: {
type: 'email'
}
}
},
officelocation: {
type: String,
label: 'Location of Office',
optional:true
},
location: {
type: [LocationSchema],
optional:true
}});
有效的集合钩子:
Providers.after.update(function (userId, doc) {
var oldDoc = this.previous;
Providers.direct.update({_id: doc._id},{$set: {location:{
type:'Point',
coordinates:[0,0]
}}});
});
不起作用的集合钩子。理想情况下,我不应该在集合更新后更新,但想确保它有效:
Providers.after.update(function (userId, doc) {
var oldDoc = this.previous;
var array=[];
var iArray=doc.officelocation.split(",");
array.push(Number(iArray[1]));
array.push(Number(iArray[0]))
Providers.direct.update({_id: doc._id},{$set: {location:[{
type:'Point',
coordinates:array
}]}});
});