$eq - Amazon DocumentDB

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

$eq

Amazon DocumentDB の $eq演算子は、フィールドの値が指定された値と等しいドキュメントを照合するために使用されます。この演算子は、 find()メソッドで一般的に使用され、指定された条件を満たすドキュメントを取得します。

パラメータ

  • field : 等価条件をチェックするフィールド。

  • value : フィールドと比較する値。

例 (MongoDB シェル)

次の例は、 $eq演算子を使用して、 nameフィールドが と等しいすべてのドキュメントを検索する方法を示しています"Thai Curry Palace"

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

db.restaurants.insertMany([ { name: "Thai Curry Palace", cuisine: "Thai", features: ["Private Dining"] }, { name: "Italian Bistro", cuisine: "Italian", features: ["Outdoor Seating"] }, { name: "Mexican Grill", cuisine: "Mexican", features: ["Takeout"] } ]);

クエリの例

db.restaurants.find({ name: { $eq: "Thai Curry Palace" } });

出力

{ "_id" : ObjectId("68ee586f916df9d39f3d9414"), "name" : "Thai Curry Palace", "cuisine" : "Thai", "features" : [ "Private Dining" ] }

コードの例

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

Node.js
const { MongoClient } = require('mongodb'); async function findByName(name) { 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('restaurants'); const results = await collection.find({ name: { $eq: name } }).toArray(); console.log(results); await client.close(); } findByName("Thai Curry Palace");
Python
from pymongo import MongoClient def find_by_name(name): 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["restaurants"] results = list(collection.find({ "name": { "$eq": name } })) print(results) client.close() find_by_name("Thai Curry Palace")