I would like to add a new ListField EmbeddedDocument to an existing ListField EmbeddedDocument. In other words, adding a new document to the list related to the document in the list.
My model: a message can contain several comments, each comment can have several comments:
class Post(Document): txt = StringField() comments = ListField(EmbeddedDocumentField(Comment)) class Comment(EmbeddedDocument): comment = StringField() comment_id = ObjectIdField() likes = ListField(EmbeddedDocumentField(Like)) class Like(EmbeddedDocument): user = ReferenceField(User) date = DateTimeField(default=datetime.utcnow,required=True)
My Code: (the command 'append' dosen't does not exist, only 'set' exists)
def appendNewLike(): user = {..} target = ObjectId(commentId) newLike = Like(user=user) Product.objects(comments__comment_id=target).update(append_comments__S__likes=newLike)
An ideal solution would look something like this:
def appendNewLike(): user = {..} target = ObjectId(commentId) newLike = Like(user=user) Product.objects(comments__comment_id=target).comments.likes.append(newLike)
Comments? Suggestions?
append mongodb mongoengine
rat
source share