-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmongoEngine.py
More file actions
28 lines (24 loc) · 819 Bytes
/
mongoEngine.py
File metadata and controls
28 lines (24 loc) · 819 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from mongoengine import *
connect('mongoengine_test', host='localhost', port=27017)
#Defining a document
import datetime
class Post(Document):
title = StringField(required=True, max_length=200)
content = StringField(required=True)
author = StringField(required=True, max_length=50)
published = DateTimeField(default=datetime.datetime.now)
#Saving the Document
post_1 = Post(
title='Sample Post',
content='Some engaging content',
author='Scott'
)
post_1.save() # This will perform an insert
print(post_1.title)
post_1.title = 'A Better Post Title'
post_1.save() # This will perform an atomic edit on "title"
print(post_1.title)
post_2 = Post(content='Content goes here', author='Michael')
post_2.title = 'Title updated'
post_2.save()
print(post_2)