我有这个数据结构。我想将一个新兄弟推送到一个特定的成员兄弟阵列:
const FamilySchema = mongoose.Schema({
username: { type: String, required: true },
family_name: { type: String, required: true },
password: { type: String, required: true },
members: [
{
fname: { type: String, required: true },
lname: { type: String, required: true },
mname: { type: String },
birth_date: { type: String },
birth_town: { type: String },
birth_state: { type: String },
death_date: { type: String },
death_town: { type: String },
death_state: { type: String },
short_bio: { type: String },
long_bio: {type: String },
parents: [
{
parent_id: { type: String, required: true }
}
],
siblings: [
{
sibling_id: { type: String, required: true }
}
],
children: [
{
children_id: { type: String, required: true }
}
],
pictures: [
{
url: { type: String, required: true }
}
],
}
]
});
我想在一个较大的家庭文档中为一个SPECIFIC成员推送一个新兄弟进入兄弟数组。我试图这样做,但它不起作用。
Family
.update(
{
_id: FAMILY_ID,
"members._id" : MEMBER_ID
},
{
$push : {
"members.$.siblings" : {
"sibling_id": THE_VALUE_I_WANT_ADDED
}
}
}
);
有什么想法?我的猫鼬知识让我失望。