当值不存在时,我想在子文档的数组中插入一个值。我有一个像这样的集合
{
"_id" : ObjectId("57ff25a74be508216afa9e03"),
"RTODetails" : [
{
"pincode" : "34tgefgef",
"state_name" : "Assam",
"PUCDetails" : [
{
"PUC_number" : "PUC755757",
"puc_year" : "2016"
}
]
}
]
}
我想在PUCDetails下添加另一个数组,如
{
"_id" : ObjectId("57ff25a74be508216afa9e03"),
"RTODetails" : [
{
"pincode" : "34tgefgef",
"state_name" : "Assam",
"PUCDetails" : [
{
"PUC_number" : "PUC755757",
"puc_year" : "2016"
},
{
"PUC_number" : "PUC755757111",
"puc_year" : "2017"
}
]
}
]
}
我正在使用
db.collection('vehicleDetails').update(
{ "_id": new ObjectId('57ff25a74be508216afa9e03') },
{
$push: {
"RTODetails.$.PUCDetails":{
"PUC_number" : "PUC755757111",
"puc_year" : "2017"
}
}
}
)
但它不起作用。