Java Code Examples for com.mongodb.DB.getCollectionNames()

The following are Jave code examples for showing how to use getCollectionNames() of the com.mongodb.DB class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: aet   File: MongoDBClient.java   View Source Code Vote up 5 votes
private Set<String> getCollectionsList(String dbName) {
  Set<String> result = Collections.emptySet();
  DB db = getDB(dbName);
  if (db != null) {
    result = db.getCollectionNames();
  }

  return result;
}
 
Example 2
Project: spring-usc   File: TestMongoDB.java   View Source Code Vote up 5 votes
public static void main(String[] args) {
		
		try {
			MongoClient mongoClient = new MongoClient( "localhost" , 27017 );
			
			DB db = mongoClient.getDB( "test" );
			
//			boolean auth = db.authenticate(myUserName, myPassword);
			
			Set<String> colls = db.getCollectionNames();

			for (String s : colls) {
			    System.out.println(s);
			}
			
			DBCollection coll = db.getCollection("testData");
			
			DBObject myDoc = coll.findOne();
			System.out.println(myDoc);
			
			DBCursor cursor = coll.find();
			try {
			   while(cursor.hasNext()) {
			       System.out.println(cursor.next());
			   }
			} finally {
			   cursor.close();
			}
			
		} catch (UnknownHostException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}