

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

# \$1all
<a name="all"></a>

Amazon DocumentDB の `$all`演算子は、フィールドの値が配列であり、配列内の要素の順序に関係なく、指定されたすべての要素を含むドキュメントを一致させるために使用されます。

**パラメータ**
+ `field`: チェックするフィールドの名前。
+ `[value1, value2, ...]`: 配列内で一致する値のリスト。

 

**`$all`式`$elemMatch`内での の使用**

`$all` 式内での `$elemMatch`演算子の使用に関する制限[`$all` 式内での `$elemMatch` の使用](functional-differences.md#functional-differences.elemMatch)については、「」を参照してください。

 

**フィールド名のドル (\$1)**

ネストされたオブジェクトの `$all`の`$`プレフィックス付きフィールドのクエリに関する制限[フィールド名のドル (\$1) とドット (.)](functional-differences.md#functional-differences-dollardot)については、「」を参照してください。

## 例 (MongoDB シェル)
<a name="all-examples"></a>

次の例は、「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" 
  ]
}
```

## コードの例
<a name="all-code"></a>

`$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()
```

------