Skip to content

Instantly share code, notes, and snippets.

@esedor
Created November 4, 2011 19:00
Show Gist options
  • Save esedor/1340180 to your computer and use it in GitHub Desktop.
Save esedor/1340180 to your computer and use it in GitHub Desktop.
New MongoDB Connection in Java
import com.mongodb.*;
MongoURI uri = new MongoURI("mongodb://user:pass@localhost:27017/dbname");
DB db = uri.connectDB();
boolean auth = db.authenticate(uri.getUsername(), uri.getPassword());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment