I have several collections, for example:
members
id
name
emails
memberid
I want to delete the email address for this member. In SQL, I could use a nested query, for example:
delete emails
where memberid in (select id from members where name = "evanmcdonnal")
In mongo, I try something like this;
db.emails.remove( {"memberid":db.members.find( {"name":"evanmcdonnal"}, {id:1, _id:0} ) )
But it does not return results. Therefore, I took a subquery and ran it myself. I believe that it returns:
{
"id":"myMadeUpId"
}
What - if internal queries are executed first - asks me a request:
db.emails.remove( {"memberid":{ "id""myMadeUpId"} )
When I really need an id value. I tried using dictionary and dot notations to access the id value without any luck. Is there a way to do this, similar to my requested request above?
source
share