$all - Amazon DocumentDB

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

$all

Amazon DocumentDB의 $all 연산자는 필드 값이 배열이고 배열의 요소 순서에 관계없이 지정된 모든 요소를 포함하는 문서를 일치시키는 데 사용됩니다.

파라미터

  • field: 확인할 필드의 이름입니다.

  • [value1, value2, ...]: 배열에서 일치시킬 값의 목록입니다.

 

$all 표현식 $elemMatch 내에서 사용

$all 표현식 내에서 $elemMatch 연산자를 사용하는 것과 관련된 $all 표현식 내에서 $elemMatch 사용 제한 사항은 섹션을 참조하세요.

 

필드 이름의 달러($)

중첩된 객체에서의 $ 접두사 필드 쿼리$all와 관련된 필드 이름의 달러($) 및 점(.) 제한 사항은 섹션을 참조하세요.

예제(MongoDB 쉘)

다음 예제에서는 "Colors" 필드가 "Red"와 "Blue"가 모두 포함된 배열인 문서를 검색하는 데 $all 연산자를 사용하는 방법을 보여줍니다.

샘플 문서 생성

db.example.insertMany([ { "Item": "Pen", "Colors": ["Red", "Blue", "Green"] }, { "Item": "Notebook", "Colors": ["Blue", "White"] }, { "Item": "Poster Paint", "Colors": ["Red", "Yellow", "White"] } ])

쿼리 예제

db.example.find({ "Colors": { $all: ["Red", "Blue"] } }).pretty()

출력

{ "_id" : ObjectId("6137d6c5b3a1d35e0b6ee6ad"), "Item" : "Pen", "Colors" : [ "Red", "Blue", "Green" ] }

코드 예제

$all 명령을 사용하기 위한 코드 예제를 보려면 사용하려는 언어의 탭을 선택합니다.

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('example'); const result = await collection.find({ "Colors": { $all: ["Red", "Blue"] } }).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['example'] result = list(collection.find({ "Colors": { "$all": ["Red", "Blue"] } })) print(result) client.close() example()