Hi I am new to mongodb.. My problem is to append array in mongodb data
My array
{
"_id" : ObjectId("5864f61111115810fc011111"),
"estimate" : {
"estimate_id" : 1122332,
"source_data" : {
"1" : {
"test":"test"
}
}
},
"updated_at" : ISODate("1970-01-15T10:47:01.399Z"),
"created_at" : ISODate("1970-01-15T10:41:56.623Z")
}
I want to add array in source_data like bellow
{
"_id" : ObjectId("5864f61111115810fc011111"),
"estimate" : {
"estimate_id" : 1122332,
"source_data" : {
"1" : {
"name":"nikhil"
},
"2" : {
"name":"nikhil"
}
}
},
"updated_at" : ISODate("1970-01-15T10:47:01.399Z"),
"created_at" : ISODate("1970-01-15T10:41:56.623Z")
}
I have tried below code but not working
$data = array("2"=>array("name":"nikhil"));
$sourcing = Sourcing::find('5864f61111115810fc011111');//return mongo data
$sourcing->put('estimate.source_data.2',$data );