在下面的程序getDatabaseNames()
中返回一个值列表并getCollectionNames()
返回一组值。为什么不都返回 a Set
?
这是否意味着我们可以创建具有相同名称的数据库?
package demo;
import java.util.List;
import java.util.Set;
import com.mongodb.DB;
import com.mongodb.MongoClient;
public class Collections2 {
public static void main(String[] args) {
MongoClient client=null;
try {
client=new MongoClient();
//Lists all the database names
System.out.println("List of databases ");
List<String> DBset=client.getDatabaseNames();
for(String string:DBset){
System.out.println(string);
}
//list all the collection names in school DB
DB db=client.getDB("school");
System.out.println("List of collections in school DB");
Set<String> set=db.getCollectionNames();
for (String string:set) {
System.out.println(string);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}