Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Updating an embedded document in mongoengine

I have a class in mongoengine

class Post(EmbeddedDocument):
        uid = StringField(required=True)
        text = StringField(required=True)
        value = StringField()

class Feed(Document):
        label = StringField(required=True)
        feed_url = StringField(required=True)
        posts = ListField(EmbeddedDocumentField(Post))

I am trying to update the Post EmbeddedDocument property name text from a certain "Parent" document. As a first step, I retrieve the Feed Document

model = Feed.objects(_id="....").first()

and then I want to update the property text of the embedded document "Post".

How can I achieve it with mongoengine?

like image 671
hoangvu68 Avatar asked Jan 05 '13 09:01

hoangvu68


1 Answers

I resolved it :)

Feed.objects(_id="...", posts__text="findvalue").update(set__posts__S__value="updatevalue")
like image 157
hoangvu68 Avatar answered Nov 14 '22 07:11

hoangvu68