Below is the JSON file and I am trying to change the key name in offers from ‘_id’ to ‘id’
[{
"offers": [{
"i": "",
"a":
"e": 25.3,
"c": "A new concept in the ed-tech market. I can relate with the importance of the Learn By Doing philosophy. Keep up the Good Work! Definitely interested to work with you to scale the vision of the company!",
"_id": "62565340aa2519d6cc33e791"
}],
"id": "62565340aa2519d6cc33e790"
},
{
"er": "#3",
"p": "Title #3",
"p": "Idea #3",
"at": ,
"equity": 25.3,
"offers": [],
"id": "6256533baa2519d6cc33e78f"
}
]
I am new to Node js
I am able to change the ‘id’ key outside of every pitch but not inside ‘offers’ key.
Can someone please help me in this.
3
Answers
Try to change your code like this:
Your answer is almost right. Use double for loop.
do it in mongo query
mongoplayground
OPTION 1
as explained here You can change key name while returning query result from mongodb using aggregation.
orginal data:
query:
query result:
OPTION 2
you can use lodash and
_.transform
as explained here