Pravitha V
Pravitha V

Reputation: 3308

Deleting a row from an embedded document in mongo engine

I have a document called login_info. It has two fields:

Location is an embedded document with two fields:

There are datas in the embedded document and i want to delete a row from it. for eg: i have to delete all the rows with location "Canada". How can i do this in mongo engine ? any help

Upvotes: 0

Views: 488

Answers (1)

jamjam
jamjam

Reputation: 3269

Try this

db.login_info.update({}, {$pull:{location:{city:"Canada"}}})

Ok try this instead

db.login_info.update( { "location.city" : { $exists : true } }, { $unset : { "location.city" : "Canada" } }, false, true);

This will remove all "rows" where city is "Canada".

Upvotes: 1

Related Questions