Skip to content

Instantly share code, notes, and snippets.

@dalmat36
Last active August 29, 2015 14:18
Show Gist options
  • Select an option

  • Save dalmat36/feb6b88a44d97cff7db6 to your computer and use it in GitHub Desktop.

Select an option

Save dalmat36/feb6b88a44d97cff7db6 to your computer and use it in GitHub Desktop.
This snippet of code connects to MongoDB running on a local machine and gets the "people" collection from the "mydb" database. (collection is defined as a global variable here)
MongoClient mongoClient = new MongoClient( "localhost" , 27017 );
MongoDatabase database = mongoClient.getDatabase("mydb");
collection = database.getCollection("people");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment