0

Meteor でシンプル スキーマ、コレクション フック、および Autoform パッケージを使用しています。更新後のコレクション フックでスキーマの埋め込みオブジェクトを更新しようとしています。私はばかげたことをしているかもしれないと感じていますが、この問題を解決できませんでした。保存中に例外が発生します: Exception while invoking method '/providers/update' Error: 0 must be an integer My schema:

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

1 に答える 1