1
$ setを使用してMongoDBコレクションを更新しようとしています。コレクション内のフィールドは存在しません。フィールドを追加しようとすると、コレクションはデータを一時的に保存し、データが消えてエラーClientError: name.first is not allowed by the schema
を返します。私はここで間違って何をしているのか分からず、私は数時間Googleを検索してきました。シンプルスキーマが更新されない
私が使用している:
- 流星
- シンプルスキーマ(NPM)
- 流星-コレクション2コア
パス:Simple-Schema
const ProfileCandidateSchema = new SimpleSchema({
userId: {
type: String,
regEx: SimpleSchema.RegEx.Id,
},
createdAt: {
type: Date,
},
name: { type: Object, optional: true },
'name.first': { type: String },
});
パス:Method.js
import { Meteor } from 'meteor/meteor';
import { ProfileCandidate } from '../profileCandidate';
import SimpleSchema from 'simpl-schema';
import { ValidatedMethod } from 'meteor/mdg:validated-method';
export const updateContactDetails = new ValidatedMethod({
name: 'profileCandidate.updateContactDetails',
validate: new SimpleSchema({
'name.first': { type: String },
}).validator({ clean: true }),
run(data) {
ProfileCandidate.update({userId: this.userId},
{$set:
{
name: {'first': "Frank"},
}
}, (error, result) => {
if(error) {
console.log("error: ", error)
}
});
}
});
UPDATE
パス:call function
updateContactDetails.call(data, (error) => {
if (error) {
console.log("err: ", error);
console.log("err.error: ", error.error);
}
});
これは機能しませんでした。エラー 'メソッド' profileCandidate.updateContactDetails 'を呼び出す際の例外ClientError:name.firstはスキーマによって許可されていません。 at Array.forEach'を呼び出します。上記のProfileCandidate.callを追加します。 – bp123
それはあなたが欲しいものですか? – bp123
それはうまくいくようです。私は実際にバリデータ関数を理解していません。 – bp123