Message from @redd

Discord ID: 430599984098836490


2018-04-03 04:51:23 UTC  

It's return a stringified JSON.

2018-04-03 05:16:21 UTC  

File is a `mongoose` schematic object, basically it is a class that abstracts a connection to a MongoDB collection

2018-04-03 05:16:48 UTC  

so it usually makes it easy to get records from the database

2018-04-03 05:17:03 UTC  

in this case it finds the one record with a specified ID

2018-04-03 05:17:18 UTC  

the data is returned and, when tested is an object

2018-04-03 05:17:39 UTC  

but for some reason when I push it to an array it goes ape shit and becomes a human readable string

2018-04-03 05:19:02 UTC  

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

2018-04-03 05:19:22 UTC  

I cannot for the life of me figure out why this fucks with the objects

2018-04-03 05:25:12 UTC  

A class that retrieves data from a database, called `File`?

2018-04-03 05:25:14 UTC  

Holy crap.

2018-04-03 05:25:46 UTC  

```js
getByUploadId: function(uploadId) {
return this.findOne({
uploadId
});
},
```

2018-04-03 05:26:12 UTC  

Now you check `findOne()`.

2018-04-03 05:26:33 UTC  

no it returns an object

2018-04-03 05:26:57 UTC  

and `typeof imageData` was === 'object

2018-04-03 05:29:22 UTC  

literally going bald from the amount of hair I am tearing out over here

2018-04-03 05:29:38 UTC  

What happens if you replace
```js
imageInfo.push(imageData);
```
by
```js
imageInfo = [imageData];
```

2018-04-03 05:29:50 UTC  

wut

2018-04-03 05:30:20 UTC  

in this case there could be multiple files...

2018-04-03 05:30:32 UTC  

do you mean just for testing?

2018-04-03 05:30:32 UTC  

For debugging purposes.

2018-04-03 05:30:36 UTC  

k

2018-04-03 05:32:29 UTC  

same result

2018-04-03 05:34:34 UTC  

Double check everything. `console.log()` imageData, imageInfo and productRecord every time one of them changes.

2018-04-03 05:35:08 UTC  

You know, sometimes one forgets to save the source code before running it again, and it looks like it's not making sense, etc.

2018-04-03 05:36:40 UTC  

it autosaves lol

2018-04-03 05:39:32 UTC  

```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;```

2018-04-03 05:40:42 UTC  

added a few more tests

2018-04-03 05:41:33 UTC  

for some dumb reason, the object is fucked when I try to save it to an already existing object

2018-04-03 05:42:02 UTC  

this is insane

2018-04-03 05:42:24 UTC  

if I put this on StackOverflow they will probably be all over this shit

2018-04-03 05:44:12 UTC  

Yeah, do that.

2018-04-03 05:44:50 UTC  

Replace the `await File.getByUploadId(uploadId);` by some random arbitrary, hardcoded, object.

2018-04-03 05:45:07 UTC  

Gotta isolate what's making it fuck everything up.

2018-04-03 05:45:22 UTC  

`let imageData = { ....};`

2018-04-03 05:46:02 UTC  

My gut tells me, if it's touching Mongo, it's suspicious. Mongo is a steaming pile of shit.

2018-04-03 05:46:02 UTC  

>js
I'll just go die brb

2018-04-03 05:48:41 UTC  

Reminder that their Java driver would connect through a thread pool, that could inadvertently return errors from random unrelated connections.

2018-04-03 05:49:30 UTC  

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.)

2018-04-03 06:08:30 UTC  
2018-04-03 06:09:03 UTC  

AMD is trying to secure drone contracts.

2018-04-03 06:10:18 UTC  

Skynet isn't sentient after all, it's all Russian hackers.