Last active
December 15, 2015 18:49
-
-
Save 89465127/5306564 to your computer and use it in GitHub Desktop.
The "Hello World" of Java and MongoDB
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Jongo.java | |
import com.mongodb.Mongo; | |
import com.mongodb.MongoClient; | |
import com.mongodb.MongoException; | |
import com.mongodb.WriteConcern; | |
import com.mongodb.DB; | |
import com.mongodb.DBCollection; | |
import com.mongodb.BasicDBObject; | |
import com.mongodb.DBObject; | |
import com.mongodb.DBCursor; | |
import com.mongodb.ServerAddress; | |
import java.net.UnknownHostException; | |
import java.util.Set; | |
public class Jongo { | |
public static void main(String[] args) throws UnknownHostException { | |
MongoClient mongoClient = new MongoClient( "localhost" ); | |
DB db = mongoClient.getDB( "my_collection" ); | |
Set<String> colls = db.getCollectionNames(); | |
for (String s : colls) { | |
System.out.println(s); | |
} | |
} | |
} | |
// Compile and run me with: | |
// javac -cp mongo-2.10.1.jar Jongo.java && java -cp .:mongo-2.10.1.jar Jongo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment