请问Mongoengine如何查询ListField内不包含指定值的结果,,class Post(D
请问Mongoengine如何查询ListField内不包含指定值的结果,,class Post(D
class Post(Document) tags = ListField(StringField())
tags 可以是 ["php", "python", "perl"],还可以是 ["ruby", "java"] 之类的
假设,我要列出 tags 里所有不包含 php 的 post,应该怎么写查询?
其实就用 $ne 就好了。
from pymongo import MongoClientclient = MongoClient("mongodb://127.0.0.1")db = client["your-db"]collection = db["your-collection"]iter = collection.find({ "tags": { "$ne": "php", },})
用 $nin
Consider the following query:
If the field holds an array, then the $nin operator selects the documents whose field holds an array with no element equal to a value in the specified array (e.g. , , etc.).
Post.objects(tags__ne='php')
编橙之家文章,
相关内容
- Python 导入包错误ImportError: No module named...,importerrorna
- 用python方法截获来访者信息有什么框架支持?,python来访
- 请问BundleInstall命令安装'gmarik/vundle'插件不成功怎么解决
- 用户中心系统哪种最适合Python/PHP使用,用户中心pytho
- 请问tornado authenticated的实现原理是什么,,哪位看过to
- 64位操作系统的Python装x86还是x64好?,pythonx64,突然间想起
- django里面同样一个url网址 用runserver请求正常,用httpd请
- Django项目版本升级如何操作?,django项目版本操作,如何
- 使用python的类报错TypeError: say() takes exactly 2 arguments (3
- 为什么我列表最后一项没有遍历到呢?,列表,为何遍历
评论关闭