$toUpper - Amazon DocumentDB

Terjemahan disediakan oleh mesin penerjemah. Jika konten terjemahan yang diberikan bertentangan dengan versi bahasa Inggris aslinya, utamakan versi bahasa Inggris.

$toUpper

$toUpperOperator di Amazon DocumentDB digunakan untuk mengonversi string ke huruf besar.

Parameter

  • expression: Ekspresi string untuk mengkonversi ke huruf besar.

Contoh (MongoDB Shell)

Contoh berikut menunjukkan penggunaan $toUpper operator untuk mengkonversi Desk bidang ke huruf besar.

Buat dokumen sampel

db.locations.insertMany([ { "_id": 1, "Desk": "düsseldorf-bvv-021" }, { "_id": 2, "Desk": "munich-hgg-32a" } ]);

Contoh kueri

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

Keluaran

{ "_id" : 1, "item" : "DüSSELDORF-BVV-021" } { "_id" : 2, "item" : "MUNICH-HGG-32A" }

Contoh kode

Untuk melihat contoh kode untuk menggunakan $toUpper perintah, pilih tab untuk bahasa yang ingin Anda gunakan:

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('locations'); const result = await collection.aggregate([ { $project: { item: { $toUpper: '$Desk' } } } ]).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['locations'] result = list(collection.aggregate([ { '$project': { 'item': { '$toUpper': '$Desk' } } } ])) print(result) client.close() example()