【发布时间】:2016-06-08 18:06:06
【问题描述】:
我正在尝试在自动表单插入另一个集合 (Meteor.users) 后插入用户配置文件数组。
我的简单模式数组是这样设置的 - (在配置文件架构内)
listings: {
type: [String],
optional: true
},
"listings.$.id": {
type: String,
optional: true
}
这是我的集合挂钩方法,应该在列出插入后插入。
//Add listing to user collection on submit
Listings.after.insert(function(userId, doc) {
console.log("STUFF");
Meteor.users.update({_id : userId},
{
$push :
{
'profile.listings.$.id' : this._id
}
}
在我看来,这应该可行。表单在没有集合挂钩的情况下正确插入,但现在当我提交表单时,我在 JS 控制台中收到此错误:
错误:过滤掉不在模式中的键后,您的修饰符现在为空(...)
console.log("stuff") 触发,我在报错前的控制台中看到了。
有人对如何做到这一点有任何想法吗?
编辑 - 通过将其切换为修复了一些问题:
Listings.after.insert(function(userId, doc) {
console.log("STUFF" + userId + ' ' + this._id);
Meteor.users.update({_id: userId },
{
$set :
{
"profile.listings.$.id" : this._id
}
}
) });
现在由于 $ 运算符,我无法插入到数组中。
【问题讨论】:
标签: arrays mongodb meteor meteor-autoform meteor-collection-hooks