for post in Post.objects(tags='mongodb'):
print(post.title)
for post in Post(tags='mongodb'): print(post.title)
for post in Post._get_collection().find({}):
print postfor post in Post._find_collection().find({}):
print post>>> for post in Post._get_collection().find({}):... print post...{u'content': u'Took a look at MongoEngine today, looks pretty cool.', u'author': ObjectId('58f7ac317a2f2e4352167a8a'), u'_id': ObjectId('58f7ac3e7a2f2e4352167a8b'), u'_cls': u'Post.TextPost', u'title': u'Fun with MongoEngine'}{u'link_url': u'http://docs.mongoengine.com/', u'author': ObjectId('58f7ac1d7a2f2e4352167a89'), u'_id': ObjectId('58f7ac3e7a2f2e4352167a8c'), u'_cls': u'Post.LinkPost', u'title': u'MongoEngine Documentation'}{u'content': u'Took a look at MongoEngine today, looks pretty cool.', u'author': ObjectId('58f7ac317a2f2e4352167a8a'), u'_id': ObjectId('58f7b4127a2f2e4352167a8d'), u'_cls': u'Post.TextPost', u'title': u'Fun with MongoEngine'}{u'link_url': u'http://docs.mongoengine.com/', u'author': ObjectId('58f7ac1d7a2f2e4352167a89'), u'_id': ObjectId('58f7b41e7a2f2e4352167a8e'), u'_cls': u'Post.LinkPost', u'title': u'MongoEngine Documentation'}{u'content': u'Took a look at MongoEngine today, looks pretty cool.', u'author': ObjectId('58f8a9b37a2f2e4b482e2b93'), u'_id': ObjectId('58f8a9bb7a2f2e4b482e2b94'), u'_cls': u'Post.TextPost', u'title': u'Fun with MongoEngine'}{u'link_url': u'http://docs.mongoengine.com/', u'author': ObjectId('58f8a99c7a2f2e4b482e2b92'), u'_id': ObjectId('58f8a9bb7a2f2e4b482e2b95'), u'_cls': u'Post.LinkPost', u'title': u'MongoEngine Documentation'}>>> for post in Post._find_collection().find({}):... print post...Traceback (most recent call last): File "<stdin>", line 1, in <module>AttributeError: type object 'Post' has no attribute '_find_collection'>>>>>> from mongoengine import *>>> connect('tumblelog')MongoClient(host=['localhost:27017'], document_class=dict, tz_aware=False, connect=True, read_preference=Primary())>>> class User(Document):... email = StringField(required=True)... first_name = StringField(max_length=50)... last_name = StringField(max_length=50)...>>> class Post(Document):... title = StringField(max_length=120, required=True)... author = ReferenceField(User)... meta = {'allow_inheritance': True}...>>> class TextPost(Post):... content = StringField()...>>> class ImagePost(Post):... image_path = StringField()...>>> class LinkPost(Post):... link_url = StringField()...>>> class Post(Document):... title = StringField(max_length=120, required=True)... author = ReferenceField(User)... tags = ListField(StringField(max_length=30))...>>> class Comment(EmbeddedDocument):... content = StringField()... name = StringField(max_length=120)...>>> class Post(Document):... title = StringField(max_length=120, required=True)... author = ReferenceField(User)... tags = ListField(StringField(max_length=30))... comments = ListField(EmbeddedDocumentField(Comment))...>>> class Post(Document):... title = StringField(max_length=120, required=True)... author = ReferenceField(User, reverse_delete_rule=CASCADE)... tags = ListField(StringField(max_length=30))... comments = ListField(EmbeddedDocumentField(Comment))...>>> ross = User(email='ro...@example.com', first_name='Ross', last_name='Lawley').save()>>> john = User(email='jo...@example.com', first_name='John', last_name='Smithe').save()>>> post1 = TextPost(title='Fun with MongoEngine', author=john)>>> post1.content = 'Took a look at MongoEngine today, looks pretty cool.'>>> post1.tags = ['mongodb', 'mongoengine']>>> post1.save()<TextPost: TextPost object>>>>>>> post2 = LinkPost(title='MongoEngine Documentation', author=ross)>>> post2.link_url = 'http://docs.mongoengine.com/'>>> post2.tags = ['mongoengine']>>> post2.save()Depends on whether you're editing it using its primary key...
--
You received this message because you are subscribed to a topic in the Google Groups "MongoEngine Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mongoengine-users/V30PeDyIJTY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mongoengine-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.