我有一些對象使用的鍵爲updated_at
和created_at
,它們的字符串時間戳記爲2012-08-29T16:04:34-04:00
。我將它插入到MongoDB中。捕獲是每個對象可以具有可變數目的實例updated_at
和created_at
(它們在數組內)。是否有任何代碼可用於搜索數組updated_at
和created_at
並用$.created_at = new Date($.created_at)
替換值?插入JSON到MongoDB自動從字符串中轉換日期
{
"name":"thomas",
"created_at":"2012-08-29T16:04:34-04:00",
"updated_at":"2012-08-29T16:04:34-04:00",
"logs":[
{
"something":"something",
"created_at":"2012-08-29T16:04:34-04:00",
},
{
"something":"something",
"created_at":"2012-08-29T16:04:34-04:00",
},
]
}
到
{
"name":"thomas",
"created_at":new Date("2012-08-29T16:04:34-04:00"),
"updated_at":new Date("2012-08-29T16:04:34-04:00"),
"logs":[
{
"something":"something",
"created_at":new Date("2012-08-29T16:04:34-04:00"),
},
{
"something":"something",
"created_at":new Date("2012-08-29T16:04:34-04:00"),
},
]
}
這太棒了,謝謝。 – ThomasReggi
沒問題 - 這是適應形式另一回答 –