$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")