简单模式不会更新

Simple-schema wont update

我正在尝试使用 $set 更新 MongoDB 集合。集合中的字段不存在。当我尝试添加字段时,集合短暂地存储了数据,然后数据消失了,returns 出现错误 ClientError: name.first is not allowed by the schema。我不知道我在这里做错了什么,我已经搜索 google 几个小时了。

我正在使用:

路径: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)
    }
});
}
});

更新

路径:call function

updateContactDetails.call(data, (error) => {
  if (error) {
    console.log("err: ", error);
          console.log("err.error: ", error.error);
  }
});

你可以尝试替换:

validate: new SimpleSchema({
  'name.first': { type: String },
}).validator({ clean: true }),

在 Method.js 中作者:

validate: new SimpleSchema({
  name: {
    type: new SimpleSchema({
      first: String,
    }),
    optional: true,
}).validator({ clean: true }),