Message from @DanielKO
Discord ID: 430599968785432576
In this case, the blame is on whoever created that File class, no?
It's return a stringified JSON.
File is a `mongoose` schematic object, basically it is a class that abstracts a connection to a MongoDB collection
so it usually makes it easy to get records from the database
in this case it finds the one record with a specified ID
the data is returned and, when tested is an object
but for some reason when I push it to an array it goes ape shit and becomes a human readable string
the function takes a product record, then iterates the list of image upload IDs then loads info for each one. then it is supposed to replace that array with the list of file information records
I cannot for the life of me figure out why this fucks with the objects
A class that retrieves data from a database, called `File`?
Holy crap.
```js
getByUploadId: function(uploadId) {
return this.findOne({
uploadId
});
},
```
Now you check `findOne()`.
no it returns an object
and `typeof imageData` was === 'object
literally going bald from the amount of hair I am tearing out over here
What happens if you replace
```js
imageInfo.push(imageData);
```
by
```js
imageInfo = [imageData];
```
wut
in this case there could be multiple files...
do you mean just for testing?
k
same result
Double check everything. `console.log()` imageData, imageInfo and productRecord every time one of them changes.
You know, sometimes one forgets to save the source code before running it again, and it looks like it's not making sense, etc.
it autosaves lol
```js
let imageInfo = [];
for(let uploadId of productRecord.images) {
let imageData = await File.getByUploadId(uploadId);
imageInfo.push(imageData);
console.log(typeof imageData); // => object
}
console.log(typeof imageInfo); // => object
console.log(typeof imageInfo[0]); // => object
productRecord.images = imageInfo;
console.log(typeof productRecord.images); // => object
console.log(typeof productRecord.images[0]); // => string
return productRecord;```
added a few more tests
for some dumb reason, the object is fucked when I try to save it to an already existing object
this is insane
if I put this on StackOverflow they will probably be all over this shit
Yeah, do that.
Replace the `await File.getByUploadId(uploadId);` by some random arbitrary, hardcoded, object.
Gotta isolate what's making it fuck everything up.
`let imageData = { ....};`
My gut tells me, if it's touching Mongo, it's suspicious. Mongo is a steaming pile of shit.
>js
I'll just go die brb
Reminder that their Java driver would connect through a thread pool, that could inadvertently return errors from random unrelated connections.
That is, you send a command to MongoDB, it's handled by one thread, and if you request the error code, it might be handled by another thread, using a different connection, that knows nothing about the operation you just did (and might have failed, the only way to know is by checking the error code.)
AMD is trying to secure drone contracts.