[Node.JS] First ".insertOne()" fails, subsequent inserts succeed

Hello! owo7

This is probably a dumb question, but its been confusing me for the past week. I’m using MongoDB to manage perks for members in a Discord guild, and when a user is verified after joining they have their data set up for usage in the rest of the bot. Recently, when that first write occurs, it never actually writes. There’s no error thrown, nor any hint that it failed except when the other parts of the bot relying on the data fail. The weirdest part is, if the function to set up the data is called again, it works flawlessly. I’ve stepped through every line, and monitored the database on each write as I step through. The relevant code is here: MongoDB_Error_Relevant_Code.js · GitHub

I’m using mongodb v 4.2.2.

Welcome @ExperiBass_N_A :handshake:,

Would you please paste what piece of the code you think is the most relevant? Is it addMember()?

correct, addMember() is the function that actually writes to the database.

This can be rewritten as an updateOne() with {upsert:true} probably.

Hmm, didn’t see that when writing that. Thanks! Still doesn’t solve my issue of the first write not actually doing anything though.

Find a bit diff to understand the code. Would you further explain why there is no function keyword?

Oh now got it, that’s code inide an export and not executed just like that. Sorry.

Also, those functions have no return value, is that also expected?

That’s to be expected, I use JS instead of TS and the data I want is a JSON object.

Sorry about the code, I’ll add more comments once I get home.