MongoEngine的使用

from mongoengine import *   #导入所有的可用资源

基础

connect('testmongo')   #连接数据库 
class People(Document):   #声明一个类
   name = StringField(required=True)    
   age  = IntField(required=True)    
   sex  = StringField(required=True)     # True表面添加的时候,这个是必加项
   salary = IntField()
kind = People(name = 'kind',age = 20,sex = 'male')
kind.save()    ```  
##查询

for each in People.objects:
printf(each.name)
namelist = People.object(sex = 'male')
for x in namelist:

##删除

namelist.delete()


你可能感兴趣的:(MongoEngine的使用)