I'm trying to fetch an array of data from Mongoose, loop through the array and add an object to Three.js scene for each item in array.
When I try to render the scene in the browser I'm getting an error saying:
"client_world.js:37 Uncaught (in promise) TypeError: data is not iterable at getData"
However when I console log the data in the get request querying the database, it prints all of the data entries as an array, sp they must be iterable.
I think maybe the data is not arriving to the javascript file.
Here is the code to get the data from the db:
const indexVR = (req, res) => {
Upload.find({})
// .populate('Upload')
.exec(function (err, docs) {
if (err) res.send(err)
// docs.toString()
res.json(docs)
console.log(docs)
})
};
this function is in the following get req:
router.get('/indexvr', FileCtrl.indexVR);
This is the code snippet from the js file:
getData()
async function getData() {
const response = await fetch('/api/indexvr');
const data = await response.json;
console.log(data)
for (item of data) {
try {
scene.add( cube );
} catch (e) {
console.error(e)
}
}
}
nothing in logging to the console in the getData function, however the browser is reading some kind of empty json object.
.. Does anyone know what I'm doing wrong?