In this function, I am working with a mongo cursor called resources
. My goal is to restructure these resources by creating an empty object and utilizing bracket notation to store the resources. However, it seems that my simplified code is exhibiting unexpected behavior.
It's puzzling why Mongo would be affecting the outcome here, especially since typeof r.id === string
. This issue becomes even more perplexing because when I employ .forEach
on a different data structure, everything works as expected.
Just to note, I am writing in Typescript.
const restructured_resources = async(resources: any, db: any) => {
let restructured_resources: any = {}
resources.forEach((r: any) => {
const id = r.id
restructured_resources[id] = "yo"
})
console.log(restructured_resources) //{}
})