Answer the question
In order to leave comments, you need to log in
Why does an array disappear during a document update in mongoDB?
During the first write to the document, the following structure is obtained:
{
"_id": "ObjectId("53d8ae568c98c83410000003")",
"city": "nsk",
"date": "ISODate("2014-07-29T20: 00: 00.0Z")",
"forecast_now": {
"time": 1406709334,
"current_temp_c": "21,2",
"cloud_title": "ясная погода",
"precip_title": "без осадков"
},
"forecast_archieve": [
]
}
{
"_id": "ObjectId("53d8ae568c98c83410000003")",
"city": "nsk",
"date": "ISODate("2014-07-29T20: 00: 00.0Z")",
"forecast_now": {
"time": 1406709479,
"current_temp_c": "21,2",
"cloud_title": "ясная погода",
"precip_title": "без осадков"
},
"forecast_archieve": [
{
"time": 1406709334,
"current_temp_c": "21,2",
"cloud_title": "ясная погода",
"precip_title": "без осадков"
}
]
}
{
"_id": "ObjectId("53d8ae568c98c83410000003")",
"city": "nsk",
"date": "ISODate("2014-07-29T20: 00: 00.0Z")",
"forecast_archieve": {
"0": {
"time": 1406709334,
"current_temp_c": "21,2",
"cloud_title": "ясная погода",
"precip_title": "без осадков"
}
},
"forecast_now": {
"time": 1406709479,
"current_temp_c": "21,2",
"cloud_title": "ясная погода",
"precip_title": "без осадков"
}
}
$tmp_arr = $result["forecast_now"];
if (!is_null($tmp_arr)){
$new_doc = array ('$set' => array("forecast_now" => $arr), '$push' => array("forecast_archieve" => $tmp_arr));
$collection->update($result, $new_doc);
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question