python mongoengine高级用法

python mongoengine高级用法

查询

for post in Post.objects(tags='mongodb'):
    print(post.title)

num_posts = Post.objects(tags='mongodb').count()
print('Found {} posts with tag "mongodb"'.format(num_posts))


post=Post.objects(tags='mongodb').first()
print(post.title)

使用id查询

post=Post.objects.with_id('5fcdb13a19f9de7f58645bb5')
print(post.title)

不包含查询

# 包含contains 不包含not__contains
# title不包含Fun的post
post= Post.objects.filter(title__not__contains="Fun")
print(post)

https://blog.csdn.net/weixin_42042680/article/details/87909424

https://blog.csdn.net/qq_33682575/article/details/81627310

posted @ 2020-12-25 15:01  不要摸我的腰  阅读(315)  评论(0编辑  收藏  举报