Meteor 收集2不';使用$push时无法清除数据
我正在使用collection2将表单中的数据插入SimpleSchema。Collection2应该在插入之前清理数据,但是,如果使用$push插入数组,则不会清理数据。所有没有数据的字段都包含Meteor 收集2不';使用$push时无法清除数据,meteor,simple-schema,meteor-collection2,Meteor,Simple Schema,Meteor Collection2,我正在使用collection2将表单中的数据插入SimpleSchema。Collection2应该在插入之前清理数据,但是,如果使用$push插入数组,则不会清理数据。所有没有数据的字段都包含“。据我所知,不可能使用$set来清理数据。我错过了什么 代码片段:Schema const ProfileCandidateSchema = new SimpleSchema({ careerHistoryPositions: { type: Array, optional: true },
“
。据我所知,不可能使用$set来清理数据。我错过了什么
代码片段:Schema
const ProfileCandidateSchema = new SimpleSchema({
careerHistoryPositions: { type: Array, optional: true },
'careerHistoryPositions.$': { type: Object, optional: true },
'careerHistoryPositions.$.uniqueId': { type: String, optional: true },
'careerHistoryPositions.$.company': {
type: String,
optional: true,
custom: function () {
const shouldBeRequired = this.field('careerHistoryPositions.company').value;
if (!shouldBeRequired) {
// updates
if (this.isSet) {
if (this.operator === '$set' && this.value === null || this.value === '') return SimpleSchema.ErrorTypes.REQUIRED;
}
}
}
}
}, {
clean: {
filter: true,
autoConvert: true,
removeEmptyStrings: true,
trimStrings: true,
getAutoValues: true,
removeNullsFromArrays: true
}
});
代码片段:Update
const updatePosition = this.state.careerHistoryPositions.map((position) => {
ProfileCandidate.update({
_id: this.state.profileCandidateCollectionId
}, {
$push: {
'careerHistoryPositions': {
uniqueId: position.uniqueId,
company: position.company
}
}
});
});
通过在要插入的对象周围使用方括号,可以使用
$set
初始化数组:
const updatePosition = this.state.careerHistoryPositions.map((position) => {
ProfileCandidate.update(this.state.profileCandidateCollectionId, {
$set: {
careerHistoryPositions: [{
uniqueId: position.uniqueId,
company: position.company
}]
}
});
});
当我使用带方括号的$set时,它会插入
careerHistoryPositions:[]
,而不插入其他内容。没有控制台错误或服务器错误。有什么想法吗?感觉它没有通过验证。Collection2说它可以是服务器端或客户端。它必须在方法中运行吗?不,它在.insert()
.update()
等时运行。。。在任何地方都被称为。