So I am trying to add data to an already existing element in my mongoDB.
I need help figuring out the correct way to updateOne() of my elements from a collection in my db.
here is the code where I try
async function saveRole(randID, role) {
console.log(`SAVING ROLE`)
console.log(`randID: ${randID}`)
if (!randID || !role) return;
try {
await db.collection('interactionData').updateOne(
{ randID: randID },
{ $push: { roles: role } }
);
console.log(`saved to db`);
} catch (error) {
scripts.logError(error)
console.log(`ROLE not saved`);
}
}
In this case db = mongoose.connection
I am getting the result of ROLE not saved and an error of cyclic dependency detected for the await db.collection line.
below is a gist, within it is printed the complete mongoose.connection obj, just in case that might help with finding the correct path to be able to updateOne(). I have had no luck.
https://gist.github.com/Alogantucker/6cd44b84af2845544dc8c005882e2cc7