$nor - Amazon DocumentDB

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

$nor

$nor 演算子は、指定されたクエリ条件のいずれにも当てはまらないドキュメントを一致させるために使用されます。これは論理的な「NOR」オペレーションに似ています。いずれのオペランドも true でない場合、結果は true になります。

パラメータ

  • expression1: 評価する最初の式。

  • expression2: 評価する 2 番目の式。

  • expressionN: 評価する追加の式。

例 (MongoDB シェル)

次の例は、 qtyフィールドが 20 以上、 sizeフィールドが「XL」と等しくないドキュメントを取得して、 $nor演算子の使用方法を示しています。

サンプルドキュメントを作成する

db.items.insertMany([ { qty: 10, size: "M" }, { qty: 15, size: "XL" }, { qty: 25, size: "L" }, { qty: 30, size: "XL" } ])

クエリの例

db.items.find({ $nor: [ { qty: { $lt: 20 } }, { size: "XL" } ] })

出力

[ { "_id" : ObjectId("..."), "qty" : 25, "size" : "L" } ]

コードの例

$nor コマンドを使用するコード例を表示するには、使用する言語のタブを選択します。

Node.js
const { MongoClient } = require('mongodb'); async function example() { const client = await MongoClient.connect('mongodb://<username>:<password>@<cluster-endpoint>:27017/?tls=true&tlsCAFile=global-bundle.pem&replicaSet=rs0&readPreference=secondaryPreferred&retryWrites=false'); const db = client.db('test'); const collection = db.collection('items'); const result = await collection.find({ $nor: [ { qty: { $lt: 20 } }, { size: "XL" } ] }).toArray(); console.log(result); await client.close(); } example();
Python
from pymongo import MongoClient def example(): client = MongoClient('mongodb://<username>:<password>@<cluster-endpoint>:27017/?tls=true&tlsCAFile=global-bundle.pem&replicaSet=rs0&readPreference=secondaryPreferred&retryWrites=false') db = client['test'] collection = db['items'] result = list(collection.find({ '$nor': [ { 'qty': { '$lt': 20 } }, { 'size': 'XL' } ] })) print(result) client.close() example()