I am trying to remove a nested object from an array of objects called createdEvents if the createdEventId matches the id I pass to it.
This is the JavaScript query I am using:
db.collection("users").updateOne({ _id: userId }, { $pull: { createdEvents: { "createdEvents.createdEventId": eventId } } })
I have also attempted the following with no success
const deleteUserCreatedEvent = await db.collection("users").updateOne({ _id: userId }, { $pull: { createdEvents: { "createdEventId": eventId } } })
This is how my document is structured:
{
"_id": {
"$oid": "63669a7fadb92eac2df57fc9"
},
"email": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ef988e8496988e96818ad7dfaf88828e8683c18c8082">[email protected]</a>",
"emailVerified": {
"$date": {
"$numberLong": "1667668607915"
}
},
"createdEvents": [
{
"createdEventName": "pushevent",
"createdEventDate": {
"$date": {
"$numberLong": "1667913330000"
}
},
"createdEventDescription": "It's gonnam be a good one",
"createdEventWeights": [],
"createdEventId": {
"$oid": "6368222391d6001d3d2986e2"
}
}
]
}
Although the code returns true indicating success, the document remains unchanged in the database after running the query.