【发布时间】:2020-12-14 14:40:12
【问题描述】:
假设我有以下模型:
const User = mongoose.model('user', {
addresses: [
{
address_name: {
type: String,
},
country: {
type: String,
}
]
})
然后在我的 Rest Api 服务中调用 User 并更新用户的地址。
User.updateOne({
"_id": user._id
}, {
$push: {
"addresses": {
"address_name": A,
"country": CountryA
},
{
"address_name": B,
"country": CountryB
}
}
})
所以首先地址数组是空的,然后我添加了一些地址。所以逻辑应该类似于将地址对象推送到地址数组。 它现在不适合我的方式。
【问题讨论】:
标签: node.js mongodb mean-stack