AI エージェント向け: ドキュメントインデックスは https://www.mongodb.com/ja-jp/docs/llms.txt で利用できます。すべてのページの markdown バージョンは、いずれかの URL パスに .md を追加することで利用できます。
Docs Menu

db.getSigningDB()(mongoshメソッド)

db.getSiblingDB(<database>)
Parameter
タイプ
説明

database

string

MongoDB データベースの名前。

次の値を返します。

データベース オブジェクト。

shell 環境の db 変数を変更せずに別のデータベースを返すために使用されます。

このメソッドは、次の環境でホストされている配置で使用できます。

  • MongoDB Atlas: The fully managed service for MongoDB deployments in the cloud

注意

This command is supported in all MongoDB Atlas clusters. For information on Atlas support for all commands, see Unsupported Commands.

  • MongoDB Enterprise: サブスクリプションベースの自己管理型 MongoDB バージョン

  • MongoDB Community: ソースが利用可能で、無料で使用できる自己管理型の MongoDB のバージョン

You can use db.getSiblingDB() as an alternative to the use <database> helper. This is particularly useful when writing scripts using mongosh where the use helper is not available.

2 つのデータベース users と records を持つ MongoDB インスタンスを考えてみましょう。active コレクションは users データベースの一部です。requests コレクションは records データベースの一部です。

この操作は、db オブジェクトを users という名前のデータベースにポイントし、active コレクションの document count を返します。

db = db.getSiblingDB('users')
db.active.countDocuments()

次の一連の操作のように、異なるデータベースを参照する複数の db オブジェクトを作成できます。

users = db.getSiblingDB('users')
records = db.getSiblingDB('records')
users.active.countDocuments()
users.active.findOne()
records.requests.countDocuments()
records.requests.findOne()

この操作により、2 つの db オブジェクトが作成されます。各 db オブジェクトは、異なるデータベース、users または records を参照します。

データベースごとに、クエリは以下を返します。

そのデータベース内のコレクションから。

このページを評価

項目一覧