I'm having trouble deleting an entry in MongoDB based on the id variable. Even when I pass the id as a parameter to the method, it doesn't seem to work. I've double-checked the variable inside the method and I'm confident that it has the correct value. At first, I thought it might be because the variable is stored as a String, so I tried converting it to a Number, but that didn't solve the issue either. Here's the code snippet:
async function DeleteID (collectionName, threadIDString) {
const uri = "mongodb://ADDRESS";
const client = new MongoClient(uri, {
useNewUrlParser: true,
useUnifiedTopology: true,
});
try {
const threadIDNum = parseInt(threadIDString);
await client.connect();
const database = client.db("DB")
const eventCollection = database.collection(collectionName)
await eventCollection.updateOne({}, {$unset: {threadIDNum: 1}})
} finally {
await client.close();
}
}
It seems like both `threadIDNum` and `threadIDStirng` are not working within `$unset`, but manually inserting a value in their place makes the code work.