好吧,不確定mongodb是否可以做到這一點,但我需要的是將以下JSON插入到我的貨幣數據庫中。MongoDB PHP插入子數組
我們想要更新的部分是exchangehistory,我們需要保留當天匯率的所有歷史記錄。第二天例如
爲e.g
{"from":"USD","currentexchange":[{"to":"NZD","rate":"1.3194","updated":"6\/5\/20121:38am"},{"to":"KWD","rate":"0.2807","updated":"6\/5\/20121:38am"},{"to":"GBP","rate":"0.6495","updated":"6\/5\/20121:38am"},{"to":"AUD","rate":"1.0228","updated":"6\/5\/20121:38am"}],"exchangehistory":{"6\/5\/2012":[{"1:38am":[{"to":"NZD","rate":"1.3194","updated":"1:38am"}]},{"1:38am":[{"to":"KWD","rate":"0.2807","updated":"1:38am"}]},{"1:38am":[{"to":"GBP","rate":"0.6495","updated":"1:38am"}]},{"1:38am":[{"to":"AUD","rate":"1.0228","updated":"1:38am"}]}]}}
查找$ addToSet。可能的重複:http://stackoverflow.com/questions/7026483/insert-data-into-inner-array-in-mongodb –