0
我是新來NoSQL
和MongoDB
和我試圖$push
的array
到另一個領域是一個array
。
我試圖push
$dynamicInfo
到我的用戶profile.weightTracker
,這樣我可以有一個new array
到weightTracker
當前代碼推代替,但我每次刷新頁面時不push
的array
作爲new array
/運行憑證,而是重新 - 寫入當前。
任何人都可以指出我做錯了什麼?
在此先感謝。
$dynamicInfo['currentWeight'] = '83';
$user = $this->db()->users;
// Deals with the static info that just need an update
if (empty($staticInfo) == false) {
$user->update(
array('_id' => new MongoId($userId)),
array('$set' => array('profile' => $staticInfo)),
array('upsert' => True)
);
}
// Deals with the dynamic info that needs to be inserted as array
if (empty($dynamicInfo) == false) {
//$dynamicInfo['inserted_on'] = new MongoDate();
$user->update(
array('_id' => new MongoId($userId)),
array('$push' => array('profile.weightTracker' => $dynamicInfo)),
array('safe' => True)
);
}
我想先執行的一個更新的另一個根據是否自變量被設置。 –
是的,我意識到這一點。但我無法猜測你的變量的內容是什麼! – Derick
也許現在答案更清楚了? – Derick