python - Mongoengine 怎样查询 ListField 里 不包含某个 value 所有结果
ringa_lee
ringa_lee 2017-04-17 13:45:15
0
3
361
class Post(Document) tags = ListField(StringField())

tags 可以是 ["php", "python", "perl"],还可以是 ["ruby", "java"] 之类的

假设,我要列出 tags 里所有不包含 php 的 post,应该怎么写查询?

ringa_lee
ringa_lee

ringa_lee

全員に返信 (3)
伊谢尔伦

其实就用$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", }, })
いいねを押す+0
    巴扎黑
    Post.objects(tags__ne='php')
    いいねを押す+0
      伊谢尔伦

      用 $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.).

      いいねを押す+0
        最新のダウンロード
        詳細>
        ウェブエフェクト
        公式サイト
        サイト素材
        フロントエンドテンプレート
        私たちについて 免責事項 Sitemap
        PHP中国語ウェブサイト:福祉オンライン PHP トレーニング,PHP 学習者の迅速な成長を支援します!