-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
422 additions
and
233 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,8 +2,11 @@ | |
|
||
import com.mongodb.MongoClient; | ||
import com.mongodb.MongoClientURI; | ||
import com.mongodb.MongoCredential; | ||
import com.mongodb.client.MongoCollection; | ||
import com.mongodb.client.MongoCursor; | ||
import com.mongodb.client.MongoDatabase; | ||
import com.mongodb.client.MongoIterable; | ||
import org.bson.Document; | ||
|
||
/** | ||
|
@@ -24,24 +27,28 @@ public MongoCollection getCollection(String colName) { | |
return collection; | ||
} | ||
|
||
public MongoIterable<String> getCollectionNames() { | ||
// Document retVal = db.runCommand(new Document("listCollections", 1)); | ||
MongoIterable<String> retVal = db.listCollectionNames(); | ||
|
||
return retVal; | ||
} | ||
|
||
public void login(String user, String pw) throws Exception { | ||
if (user == null || pw == null) { | ||
} | ||
// To connect to mongodb server | ||
String uri = String.format("mongodb://%s:%[email protected]:53412/lookuptables", user, pw); | ||
|
||
MongoCredential mongoCredential = MongoCredential.createScramSha1Credential("admin", "admin", | ||
"admin123".toCharArray()); | ||
MongoClientURI connectionString = new MongoClientURI(uri); | ||
client = new MongoClient(connectionString); | ||
db = client.getDatabase("lookuptables"); | ||
System.out.println("Connected to database successfully!"); | ||
//boolean auth = db.authenticate(myUserName, myPassword); | ||
//System.out.println("Authentication: "+auth); | ||
|
||
try { | ||
|
||
// To connect to mongodb server | ||
String uri = String.format("mongodb://%s:%[email protected]:53412/lookuptables", user, pw); | ||
MongoClientURI connectionString = new MongoClientURI(uri); | ||
client = new MongoClient(connectionString); | ||
db = client.getDatabase("lookuptables"); | ||
System.out.println("Connect to database successfully"); | ||
//boolean auth = db.authenticate(myUserName, myPassword); | ||
//System.out.println("Authentication: "+auth); | ||
|
||
} catch (Exception e) { | ||
System.err.println(e.getClass().getName() + ": " + e.getMessage()); | ||
} | ||
} | ||
|
||
public void logout() { | ||
|
This file contains 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
This file contains 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
Oops, something went wrong.