Java MongoDB : Get collection from database
In Java, you can use db.getCollection(“your collection name”) to get a single collection to use. DBCollection collection = db.getCollection("yourCollection"); If you do not know the collection name, use db.getCollectionNames() to get the entire list of collection names from a selected database. DB db = mongo.getDB("yourdb"); Set<String> collections = db.getCollectionNames(); for (String collectionName : collections) { …