Reputation: 89
I want to delete a embedded document with a specific '_id' using flask and Mongoengine. Document have this structure:
class Main(db.Document):
title = db.StringField(max_length=156, required = True)
press = db.ListField(db.EmbeddedDocumentField(Press))
class Press(db.EmbeddedDocument):
_id= db.StringField()
date = db.DateTimeField(default = datetime.utcnow())
url = db.URLField()
title = db.StringField()
description = db.StringField()
site_name = db.StringField()
url_image = db.StringField()
author = db.StringField()
I try using:
m. = Main.objects.get_or_404(slug= request.form['slug'])
m.update_one(unset__press({'_id': request.form['_id']}))
request.form cotaind data from a html form correctly formatted.
but does'nt work!!! Any suggestion?? Thanks.
Upvotes: 0
Views: 1297
Reputation: 2925
I think you are looking for the $pull operator. Try:
m.update_one(pull__press___id=request.form['_id'])
Upvotes: 1