84669 personnes étudient
152542 personnes étudient
20005 personnes étudient
5487 personnes étudient
7821 personnes étudient
359900 personnes étudient
3350 personnes étudient
180660 personnes étudient
48569 personnes étudient
18603 personnes étudient
40936 personnes étudient
1549 personnes étudient
1183 personnes étudient
32909 personnes étudient
class Post(Document) tags = ListField(StringField())
tags 可以是 ["php", "python", "perl"],还可以是 ["ruby", "java"] 之类的
假设,我要列出 tags 里所有不包含 php 的 post,应该怎么写查询?
ringa_lee
其实就用 $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.).
其实就用
$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.).