An id is created automatically on save: profile.id , convert to string with str(profile.id)
Set id by adding primary_key=True to Field and it will be aliased to id
Images Add Photo
file = request.files['profile_image']profile.photo.new_file()profile.photo.write(file)profile.photo.close()profile.photo = current_user.profile.photocurrent_user.profile = profile#Save to DBcurrent_user.save()
Retrieve Img
img = Image.objects()[0].img.read()
Query
You need to define and import the model
#return all objects User.objects #Query in embedded docsPage.objects(author__country='uk')#only first 5 people(??throw error if not exist??)User.objects[:5]# retrieve first result or None if it doesnt existUser.objects.first()for user in User.objects(username='jfuentes'):print(user.email)
Operators
Double underscore after field to do operator
in – value is in list (a list of values should be provided)
#Query users with age less or equalUsers.objects(age__lte=18)
Advanced
Page.objects(__raw__={'tags': 'coding'})
classPage(Document): tags =ListField(StringField())# This will match all pages that have the word 'coding' as an item in the 'tags' listPage.objects(tags='coding')