MongoDB
 Computer >> コンピューター >  >> プログラミング >> MongoDB

特定のMongoDBデータベースからのすべてのコレクションを一覧表示するにはどうすればよいですか?


特定のデータベースのすべてのコレクションを一覧表示する場合は、最初にデータベースを切り替える必要があります。クエリは次のとおりです-

> use sample;
switched to db sample
> db.getCollectionNames();

以下は出力です-

[
   "copyThisCollectionToSampleDatabaseDemo",
   "deleteDocuments",
   "deleteDocumentsDemo",
   "deleteInformation",
   "employee",
   "internalArraySizeDemo",
   "sourceCollection",
   "updateInformation",
   "userInformation"
]

代替クエリは次のようになります-

> show collections;

以下は出力です-

copyThisCollectionToSampleDatabaseDemo
deleteDocuments
deleteDocumentsDemo
deleteInformation
employee
internalArraySizeDemo
sourceCollection
updateInformation
userInformation

  1. MySQLデータベース内のすべてのトリガーを一覧表示するにはどうすればよいですか?

    MySQLデータベース内のすべてのトリガーを一覧表示するには、SHOWコマンドを使用できます。クエリは次のとおりです- mysql> show triggers; 以下は出力です- +----------------+--------+----------------------+--------------------------------------------------------------------+--------+------------------------+--------------------------------------------+-------

  2. Javaを使用してMongoDBデータベース内のすべてのコレクションを一覧表示するにはどうすればよいですか?

    show collectionsを使用して、データベース内の既存のすべてのコレクションのリストを印刷できます。 例 以下に示すように、MongoDBデータベースに3つのコレクションを作成したと仮定します- > use sampleDatabase switched to db sampleDatabase > db.createCollection("students") { "ok" : 1 } > db.createCollection("teachers") { "ok" : 1 }