Example usage for com.mongodb MongoClient MongoClient

List of usage examples for com.mongodb MongoClient MongoClient

Introduction

In this page you can find the example usage for com.mongodb MongoClient MongoClient.

Prototype

public MongoClient(final MongoClientURI uri, final MongoDriverInformation mongoDriverInformation) 

Source Link

Document

Creates a Mongo described by a URI.

Usage

From source file:br.ufabc.impress.mongo.manager.DBHelper.java

private void createInstance(Mongo mongoDTO) throws UnknownHostException {
    mongoClient = new MongoClient(mongoDTO.getDatabaseUrl(), mongoDTO.getDatabasePort());
    db = mongoClient.getDB(mongoDTO.getDatabaseSchema());

}

From source file:br.ufg.inf.everemind.db.DatabaseConnection.java

License:Open Source License

private static MongoDatabase localConnection() throws UnknownHostException {
    MongoClient mongoClient = new MongoClient("localhost", 27017);
    MongoDatabase database = mongoClient.getDatabase("everemind");
    return database;
}

From source file:brooklyn.entity.nosql.mongodb.MongoDBClientSupport.java

License:Apache License

private MongoClient client() {
    return new MongoClient(address, connectionOptions);
}

From source file:brooklyn.entity.nosql.mongodb.MongoDBTestHelper.java

License:Apache License

private static MongoClient clientForServer(AbstractMongoDBServer server) {
    try {//from  w ww. ja va  2s. co m
        return new MongoClient(server.getAttribute(MongoDBServer.HOSTNAME),
                server.getAttribute(MongoDBServer.PORT));
    } catch (UnknownHostException e) {
        // Fail whatever test called this method.
        throw Throwables.propagate(e);
    }
}

From source file:bruma.tools.Isis2Mongo.java

License:Open Source License

private static DB getDatabase(final String host, final int port, final String user, final String password,
        final String mongoDb) throws IOException {
    final MongoClient mongo = new MongoClient(host, port);
    final DB db = mongo.getDB(mongoDb);

    if (user != null) {
        if (!db.authenticate(user, password.toCharArray())) {
            throw new IOException("database authentication failed");
        }/* ww w .j a  v a2  s .c om*/
    }
    return db;
}

From source file:buysell.login.java

private void loginSActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_loginSActionPerformed
    // TODO add your handling code here:
    shopping sh1 = new shopping();
    try {//from  w  w w.j  a v a2 s.c  o  m
        MongoClient mongoClient = new MongoClient("localhost", 27017);
        DB db = mongoClient.getDB("snehal");
        System.out.println("Connect to database successfully");
        DBCollection coll = db.getCollection("user");
        System.out.println("Collection created successfully");
        String name = jTextField1.getText().toString();
        String passwd = jPasswordField1.getText().toString();
        BasicDBObject searchQuery = new BasicDBObject();
        searchQuery.put("name", name);
        searchQuery.put("passwd", passwd);

        DBCursor cursor = coll.find(searchQuery);
        int i = 0;
        while (cursor.hasNext()) {
            i = 1;
            System.out.println(cursor.next());
        }
        if (i == 0) {
            JOptionPane.showMessageDialog(null, "user name or passwod is wrong");

        } else {
            System.out.println("user get");
            sh1.setVisible(true);
            dispose();
        }
        System.out.println("Document inserted successfully");
    } catch (NumberFormatException e) {
        System.out.println();
    }

}

From source file:buysell.shopping.java

private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
    // TODO add your handling code here:

    try {//from  w w  w.j a v  a 2 s  . co m
        MongoClient mongoClient = new MongoClient("localhost", 27017);
        DB db = mongoClient.getDB("buysale");
        System.out.println("Connect to database successfully");
        DBCollection coll = db.getCollection("assetes");
        System.out.println("Collection created successfully");
        //String name = jTextField1.getText().toString();
        //String email = jTextField2.getText().toString();
        //String phoneno = jTextField3.getText().toString();
        // String price= jTextField4.getText().toString();
        //String photourl = jTextField5.getText().toString();
        String check = jCheckBox1.getText().toString();
        System.out.println(check);
        String type = jComboBox1.getSelectedItem().toString();
        BasicDBObject searchQuery = new BasicDBObject();
        searchQuery.put("type", type);
        DBCursor cursor = coll.find(searchQuery);
        int i = 0;
        while (cursor.hasNext() && i != 1) {
            i++;
            DBObject obj = cursor.next();
            String name = (String) obj.get("name");
            String email = (String) obj.get("email");
            String phoneno = (String) obj.get("phoneno");
            String price = (String) obj.get("price");
            String url = (String) obj.get("photourl");
            jTextField1.setText(name);
            jTextField2.setText(email);
            jTextField3.setText(phoneno);
            jTextField4.setText(price);
            jLabel3.setIcon(new javax.swing.ImageIcon(url));
        }

        System.out.println("Document inserted successfully");
    } catch (NumberFormatException e) {
        System.out.println();
    }
}

From source file:buysell.sign.java

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    // TODO add your handling code here:

    try {//  w w  w  .ja  va2s  . c  om
        MongoClient mongoClient = new MongoClient("localhost", 27017);
        DB db = mongoClient.getDB("snehal");
        System.out.println("Connect to database successfully");
        DBCollection coll = db.getCollection("user");
        System.out.println("Collection created successfully");
        String fullname = jTextField2.getText().toString();

        String email = jTextField3.getText().toString();
        String passwd = jTextField4.getText().toString();
        System.out.println("finalproject.sign.jButton1ActionPerformed()" + fullname);
        if (jTextField2.getText().length() != 0 && jTextField3.getText().length() != 0
                && jTextField4.getText().length() != 0) {
            BasicDBObject doc = new BasicDBObject("name", fullname).

                    append("passwd", passwd);

            coll.insert(doc);

            System.out.println("Document inserted successfully");
            home h1 = new home();
            h1.setVisible(true);
            dispose();
        } else {
            JOptionPane.showMessageDialog(null, "Fill every field");
        }
    } catch (NumberFormatException e) {
        System.out.println();
    }
}

From source file:buysell.subads.java

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    // TODO add your handling code here:
    try {//from w ww  .  j a v  a2s  .  c  om
        MongoClient mongoClient = new MongoClient("localhost", 27017);
        DB db = mongoClient.getDB("buysale");
        System.out.println("Connect to database successfully");
        DBCollection coll = db.getCollection("assetes");
        System.out.println("Collection created successfully");
        String name = jTextField1.getText().toString();
        String email = jTextField2.getText().toString();
        String phoneno = jTextField3.getText().toString();
        String price = jTextField4.getText().toString();
        String photourl = jTextField5.getText().toString();
        String type = jComboBox1.getSelectedItem().toString();
        DB dB = mongoClient.getDB("snehal");
        System.out.println("Connect to database successfully");
        DBCollection colle = dB.getCollection("user");
        System.out.println("Collection created successfully");
        String uname = jTextField6.getText().toString();
        String passwd = jPasswordField1.getText().toString();
        BasicDBObject searchQuery = new BasicDBObject();
        searchQuery.put("name", uname);
        searchQuery.put("passwd", passwd);

        DBCursor cursor = colle.find(searchQuery);
        int i = 0;
        while (cursor.hasNext()) {
            i = 1;
            System.out.println(cursor.next());
        }
        if (i == 0) {
            JOptionPane.showMessageDialog(null, "user name or passwod is wrong");

        } else {
            if (jTextField2.getText().length() != 0 && jTextField3.getText().length() != 0
                    && jTextField4.getText().length() != 0 && jTextField1.getText().length() != 0
                    && jTextField5.getText().length() != 0) {

                BasicDBObject doc = new BasicDBObject("name", name).append("username", uname)
                        .append("passwd", passwd).append("email", email).append("phoneno", phoneno)
                        .append("price", price).append("type", type).append("photourl", photourl);

                coll.insert(doc);
                home h2 = new home();
                h2.setVisible(true);
                dispose();
                System.out.println("Document inserted successfully");
            } else {
                JOptionPane.showMessageDialog(null, "enter the every field");
            }
        }

    } catch (NumberFormatException e) {
        System.out.println();
    }
}

From source file:byusentiment.Byusentiment.java

public static void initialize() throws UnknownHostException {
    Byusentiment.mongoClient = new MongoClient("localhost", 27017);
    Byusentiment.db = mongoClient.getDB("byu");
    Byusentiment.coll = db.getCollection("tweets");
    //boolean auth = db.authenticate(myUserName, myPassword);
}