After accepting or canceling a friend request, I am unable to pull it from the array. It seems that when I try to do so, nothing happens.
The query matches for 1 document but no documents are actually modified.
I noticed that removing the requested_at
field from the user object resolves this issue.
Where could I be going wrong?
Sample MongoDB Document
{
"_id" : ObjectId("5cb18680aa024b2d441f93cc"),
"friends" : [],
"friend_requests" : [
{
"user" : {
"id" : ObjectId("5cb14fd7db537905c89e0a72"),
"requested_at" : ISODate("2019-04-14T17:51:00.588Z")
}
}
]
}
Related MongoDB Query
db.getCollection('users').updateOne(
{ _id: ObjectId("5cb18680aa024b2d441f93cc") },
{
$pull: {
friend_requests: {
user: {
id: ObjectId("5cb14fd7db537905c89e0a72")
}
}
}
});
Outcome
{
"acknowledged" : true,
"matchedCount" : 1.0,
"modifiedCount" : 0.0
}