Here is one example of the pull operator, using flask_mongoengine and assuming the parent object class is called Blog, and the comments are EmbeddedDocuments within Blog.
Notice the triple underscore in comments id. This is because if you want primary keys on Comments, you need to add one in your model declaration like this:
class Comment(db.EmbeddedDocument):
_id = db.ObjectIdField(primary_key=True, default=lambda: ObjectId())
...
The lamba function will generate your primary keys for you.
Here is one example of the pull operator, using flask_mongoengine and assuming the parent object class is called Blog, and the comments are EmbeddedDocuments within Blog.
Notice the triple underscore in comments id. This is because if you want primary keys on Comments, you need to add one in your model declaration like this:
The lamba function will generate your primary keys for you.
Hi you can pull items from an array:
https://github.com/hmarr/mongoengine/blob/master/tests/queryset.py#L1374
See $pull: http://www.mongodb.org/display/DOCS/Updating#Updating-%24pull
You need to use $pull operator here :
http://www.mongodb.org/display/DOCS/Updating#Updating-%24pull