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

Mongo.getDBNames()(mongoshメソッド)

Mongo.getDBNames()

使用可能なデータベースの一覧を返します。 Mongo.getDBNames()はlistDatabasesコマンドを呼び出します。

Mongo.getDBNames()メソッドはパラメータを取ります 。

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

  • MongoDB Atlas はクラウドでの MongoDB 配置のためのフルマネージド サービスです
  • MongoDB Enterprise: サブスクリプションベースの自己管理型 MongoDB バージョン

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

現在の MongoDB インスタンスで使用可能なデータベースを一覧表示します。

db.getMongo().getDBNames()

db.getMongo()メソッドは インスタンスへの接続を作成します。 Mongo.getDBNames()は次を返します。

[ 'admin', 'config', 'local', 'test' ]

コレクションのリストを取得するには、 Mongo.getDBNames()を使用します。

db.getMongo().getDBNames().map( name => db.getSiblingDB( name ).getCollectionNames())

出力例:

[ [ 'system.users', 'system.keys', 'system.version' ], [ 'settings', 'tenantMigrationRecipients', 'system.sessions', 'transactions', 'external_validation_keys', 'image_collection', 'tenantMigrationDonors', 'system.indexBuilds' ], [ 'replset.minvalid', 'system.views', 'oplog.rs', 'replset.initialSyncId', 'startup_log', 'system.replset', 'system.rollback.id', 'replset.oplogTruncateAfterPoint', 'replset.election', 'system.tenantMigration.oplogView' ], [ 'feedback', 'inventory', 'engineers', 'clothes' ]]
このページを評価

項目一覧