Please suggest me on how to insert an object inside an object. Sample collection
{
"_id" : ObjectId("57556cec9d66a6c26b19ce06"),
"email" : "[email protected]",
"password" : "1235466",
"typeOfUser" : 1,
"userDetails" : {
"firstName" : "David",
"lastName" : "Beckham",
"contactNumber" : "12345678989"
}
}
I would like to add another object called address object inside this. something like this
{
"_id" : ObjectId("57556cec9d66a6c26b19ce06"),
"email" : "[email protected]",
"password" : "1235466",
"typeOfUser" : 1,
"userDetails" : {
"firstName" : "David",
"lastName" : "Beckham",
"contactNumber" : "12345678989"
"address" : {
"country" : "",
"state" : ""
}
}
}
Please suggest me on how to insert values for address object..
What I have tried?
db.getCollection('PetCare').update({"contactNumber":"12345678989"},{"$push":{"address":{"country":"India","city":"Blore"}}})
but it does not update..