MongoDb:无法在Java中获取集合名称

时间:2017-12-11 09:44:52

标签: java mongodb

 MongoClient mongoClient = new MongoClient( "localhost" , 27017 );
 System.out.print("Conencton Successfull");
 List<String> dbs = mongoClient.getDatabaseNames();
 System.out.println(dbs);
 System.out.println("database selected");
 DB db = mongoClient.getDB("ddbb");
 Set<String> collections =  db.getCollectionNames();
 for(String coll : collections){
    System.out.println(coll);
 }

运行上面的代码,给我可用的数据库名称,但不输出集合名称。我可以通过手动选择Collection来插入文档。

输出:

Conencton[admin, ddbb, local]
database selected

POM:

<dependency>
    <groupId>org.mongodb</groupId>
    <artifactId>mongo-java-driver</artifactId>
    <version>2.12.3</version>
</dependency>

0 个答案:

没有答案