84669 person learning
152542 person learning
20005 person learning
5487 person learning
7821 person learning
359900 person learning
3350 person learning
180660 person learning
48569 person learning
18603 person learning
40936 person learning
1549 person learning
1183 person learning
32909 person learning
class Post(Document) tags = ListField(StringField())
tags 可以是 ["php", "python", "perl"],还可以是 ["ruby", "java"] 之类的
假设,我要列出 tags 里所有不包含 php 的 post,应该怎么写查询?
ringa_lee
In fact, just use $ne.
$ne
from pymongo import MongoClient client = MongoClient("mongodb://127.0.0.1") db = client["your-db"] collection = db["your-collection"] iter = collection.find({ "tags": { "$ne": "php", }, })
Post.objects(tags__ne='php')
用 $nin
Consider the following query:
db.inventory.find( { qty: { $nin: [ 5, 15 ] } } )
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.).
In fact, just use
$ne
.用 $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.).