$toLower - Amazon DocumentDB

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

$toLower

Amazon DocumentDB の $toLower演算子は、文字列を小文字に変換するために使用されます。

パラメータ

  • expression: 小文字に変換する文字列式。

例 (MongoDB シェル)

次の例は、 $toLower演算子を使用して Deskフィールドを小文字に変換する方法を示しています。

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

db.locations.insertMany([ { "_id": 1, "Desk": "Düsseldorf-BVV-021" }, { "_id": 2, "Desk": "Munich-HGG-32a" } ]);

クエリの例

db.locations.aggregate([ { $project: { item: { $toLower: "$Desk" } } } ]);

出力

{ "_id" : 1, "item" : "düsseldorf-bvv-021" } { "_id" : 2, "item" : "munich-hgg-32a" }

コードの例

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

Node.js
const { MongoClient } = require("mongodb"); async function main() { 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("locations"); const result = await collection.aggregate([ { $project: { item: { $toLower: "$Desk" } } } ]).toArray(); console.log(result); await client.close(); } main();
Python
from pymongo import MongoClient def main(): 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["locations"] result = list(collection.aggregate([ { "$project": { "item": { "$toLower": "$Desk" } } } ])) print(result) client.close() if __name__ == "__main__": main()