Java examples for Big Data:MongoDB
Read from MongoDB
import java.io.IOException; import java.net.UnknownHostException; import com.amazonaws.auth.AWSCredentials; import com.amazonaws.auth.PropertiesCredentials; import com.amazonaws.services.dynamodb.AmazonDynamoDBClient; import com.mongodb.DB; import com.mongodb.DBCollection; import com.mongodb.Mongo; import com.mongodb.MongoException; public class MongotoDynamo { static AmazonDynamoDBClient dynamoDB; public static void main(String[] args) throws IOException { init();//from w w w . j a va 2 s. c o m readfromMongo(); } private static void readfromMongo() throws UnknownHostException, MongoException { // TODO Auto-generated method stub Mongo mongo; mongo = new Mongo("10.3.4.84", 27017); mongo.getDB("db").authenticate("cssc", new char[] { '1' }); DB db = mongo.getDB("db"); String[] collectionnames = (String[]) db.getCollectionNames() .toArray(); for (int i = 0; i < collectionnames.length; i++) { System.out.println("Name of Collection: " + collectionnames[i]); DBCollection collection = db.getCollection(collectionnames[i]); } } private static void init() throws IOException { AWSCredentials credentials = new PropertiesCredentials( MongotoDynamo.class .getResourceAsStream("AwsCredentials.properties")); dynamoDB = new AmazonDynamoDBClient(credentials); } }