I have documents with the following structure
{
"_id":{"$oid":"..."},
"work_type": "ASSIGNMENT",
"materials": [
{
"driveFile": {
"driveFile": {
"id": "...",
"title": "filename",
"alternateLink": "https://drive.google.com/...",
"thumbnailUrl": "https://drive.google.com/..."
},
"shareMode": "STUDENT_COPY"
}
},
{
"youtubeVideo": {
"id": "tfdbq",
"alternateLink": "https://www.youtube.com/watch?v=..."
}
}
]
}
And I want to convert the objects in the array to JSON strings so that I can import the materials field as a repeated string column in SQL
Resulting in:
{
"_id":{"$oid":"..."},
"work_type": "ASSIGNMENT",
"materials": [
"{"driveFile":{"driveFile":{"id":"...","title":"filename","alternateLink":"https://drive.google.com/...","thumbnailUrl":"https://drive.google.com/..."},"shareMode":"COPY"}}",
"{"youtubeVideo":{"id":"tfdbq","alternateLink":"https://www.youtube.com/watch?v=..."}}""
]
}
question from:
https://stackoverflow.com/questions/65922820/how-do-i-convert-an-array-of-objects-subdocuments-to-an-array-of-strings-in-a 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…