List of usage examples for com.mongodb MongoClient MongoClient
public MongoClient(final MongoClientURI uri, final MongoDriverInformation mongoDriverInformation)
From source file:com.mycode.security.Authentication.java
public String getUserAuthenticationToken(String userName, String password) { MongoClient mongoClient = null;/*from w ww .j av a 2 s .c om*/ try { mongoClient = new MongoClient("localhost", 27017); } catch (UnknownHostException ex) { ex.printStackTrace(); } DB db = mongoClient.getDB("test"); BasicDBObject doc = new BasicDBObject().append("userName", userName).append("password", password); SecureRandom random = new SecureRandom(); String token = new BigInteger(130, random).toString(32); DBCollection userCredentials = db.createCollection("Authentication", doc); return token; }
From source file:com.mycompany.bean.PlytaService.java
public static DBCollection getConnection(String DBName, String CollectionName) throws Exception { MongoClient mongo = new MongoClient("localhost", 27017); DB db = mongo.getDB(DBName);/*from w w w .j a va 2s . co m*/ DBCollection table = db.getCollection(CollectionName); return table; }
From source file:com.mycompany.database.MongodbDataBaseClass.java
public void dududu() { System.out.println("not error"); MongoClient mongoClient = new MongoClient("localhost", 27017); MongoDatabase database = mongoClient.getDatabase("testdb"); System.out.println("not error"); MongoCollection<Document> col = database.getCollection("cars"); try (MongoCursor<Document> cur = col.find().iterator()) { while (cur.hasNext()) { Document doc = cur.next(); List list = new ArrayList(doc.values()); System.out.print(list.get(1)); System.out.print(": "); System.out.println(list.get(2)); }//from w w w. j a v a2 s . c o m } mongoClient.close(); }
From source file:com.mycompany.mongodb.tweet.SimpleClient.java
public void connect(String ip) { mongoClient = new MongoClient(ip, 27017); db = mongoClient.getDatabase("13512023"); }