Unten ist die JSON-Datei und ich versuche, den Schlüsselnamen in Angeboten von „_id" in „id" zu ändern.
[{
"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"
}
]
Ich bin neu bei Node js. Ich kann die 'id'-Taste außerhalb jeder Tonhöhe ändern, aber nicht innerhalb der 'offers'-Taste. Kann mir bitte jemand dabei helfen.
Lösung des Problems
Versuchen Sie, Ihren Code wie folgt zu ändern:
MongoClient.connect(url, function (err, db) {
if (err) throw err;
var dbo = db.db("mydb");
var coll = dbo.collection("pitches");
coll
.find({})
.sort({
_id: -1,
})
.toArray(function (err, result) {
if (err) {
response.send(err);
} else {
for (const value of res) {
for (const offer of value.offers) {
offer.id = offer._id
delete offer._id
}
}
response.statusCode = 201;
response.send(result);
}
});
});
Keine Kommentare:
Kommentar veröffentlichen