有人请帮我解决这种情况吗?
我有这个假的 JSON ......
[
{
"user": {
"type": "PF",
"code": 12345,
"Name": "Darth Vader",
"currency": "BRL",
"status": "SINGLE",
"localization": "NABOO",
"createDate": 1627990848665,
"olderAdress": [
{
"localization": "DEATH STAR",
"createDate": 1627990848775
},
{
"localization": "TATOOINE",
"createDate": 1627990555888
},
]
}
}
]
我的想法是,我需要提取“olderAdress”并创建新寄存器,但我也需要保留原始寄存器。示例:这是我希望的结果。
[
{
"_id": ObjectId("5a3456e000102030405000000"),
"user": {
"Name": "Darth Vader",
"code": 12345,
"createDate":1627990848665,
"currency": "BRL",
"localization": "NABOO",
"status": "SINGLE",
"type": "PF"
}
},
{
"_id": ObjectId("5a789e000102030405000000"),
"user": {
"Name": "Darth Vader",
"code": 12345,
"createDate": 1627990848775,
"currency": "BRL",
"localization": "DEATH STAR",
"status": "SINGLE",
"type": "PF"
}
},
{
"_id": ObjectId("5a991e000102030405000000"),
"user": {
"Name": "Darth Vader",
"code": 12345,
"createDate": 1627990555888,
"currency": "BRL",
"localization": "TATOOINE",
"status": "SINGLE",
"type": "PF"
}
}
]
我在此链接(测试以提取值)中尝试相同的想法进行测试,但不幸的是我不能。有人可以帮我吗?