MongoDB에서 show dbs 명령을 사용하여 데이터베이스 목록을 볼 수 있습니다.
> show dbs admin config local myDatabase sampleDatabase students test testDB
Java에서는 getDatabaseNames()를 사용하여 MongoDb의 모든 데이터베이스 목록을 가져올 수 있습니다. 방법.
예
import com.mongodb.client.MongoIterable;
import com.mongodb.MongoClient;
public class ListOfDatabases {
public static void main( String args[] ) {
// Creating a Mongo client
MongoClient mongo = new MongoClient( "localhost" , 27017 );
//Retrieving the list of collections
MongoIterable<String> list = mongo.listDatabaseNames();
for (String name : list) {
System.out.println(name);
}
}
} 출력
admin config local myDatabase sampleDatabase students test testDB