每次用户订阅" street"或另一个"用户"我想将他们的Id添加到当前用户的配置文件中的嵌套对象。
我尝试了以下不同的结果:
Meteor.users.update(Meteor.userId(), {
$addToSet: {
'profile.subscription': { Street : streetDis
}
}
})
这会更新配置文件,但每次都会在数组中创建一个条目:
Profile.subscription[0] : Street : "eziajepozjaoeja"
Profile.subscription[1] : Street : "eezapoezkaejz"
Profile.subscription[2] : User : "akzejpazjepza"
我想要的架构如下:
Profile.subscription.Street[0] : "eziajepozjaoeja"
Profile.subscription.Street[1]:"eezapoezkaejz"
Profile.subscription.User[0]: "akzejpazjepza"
所以我试试:
Meteor.users.update(Meteor.userId(), {
$addToSet: {
'a.profile.last.Adress': "akzejpazjepza"}
}
)
返回:更新失败:访问被拒绝
Meteor.users.update(Meteor.userId(), {
$addToSet: {
'a.profile': { last: {Adress : "akzejpazjepza"}}
}
})
这也会返回:更新失败:访问被拒绝
答案 0 :(得分:1)
如果您希望profile.subscription.streets
和profile.subscription.users
分别是一组ID,那么您应该像这样更新用户的文档:
Meteor.users.update(Meteor.userId(), {
$addToSet: {
'profile.subscription.streets': streetId,
'profile.subscription.users': userId
}
});