I want to insert a value in the array of the sub document when the value is not already there.I have a collection like this
{
"_id" : ObjectId("57ff25a74be508216afa9e03"),
"RTODetails" : [
{
"pincode" : "34tgefgef",
"state_name" : "Assam",
"PUCDetails" : [
{
"PUC_number" : "PUC755757",
"puc_year" : "2016"
}
]
}
]
}
I want to add another array under PUCDetails like
{
"_id" : ObjectId("57ff25a74be508216afa9e03"),
"RTODetails" : [
{
"pincode" : "34tgefgef",
"state_name" : "Assam",
"PUCDetails" : [
{
"PUC_number" : "PUC755757",
"puc_year" : "2016"
},
{
"PUC_number" : "PUC755757111",
"puc_year" : "2017"
}
]
}
]
}
I am using
db.collection('vehicleDetails').update(
{ "_id": new ObjectId('57ff25a74be508216afa9e03') },
{
$push: {
"RTODetails.$.PUCDetails":{
"PUC_number" : "PUC755757111",
"puc_year" : "2017"
}
}
}
)
but it's not working.