Example usage for com.mongodb Mongo close

List of usage examples for com.mongodb Mongo close

Introduction

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

Prototype

public void close() 

Source Link

Document

Closes all resources associated with this instance, in particular any open network connections.

Usage

From source file:br.rdu.ifpb.mongo.repositorio.PessoaRepositoriMongo.java

private void closeConnection(Mongo mongo) {
    mongo.close();
}

From source file:cn.vlabs.clb.server.storage.mongo.MongoStorageService.java

License:Apache License

public void close() {
    if (client != null) {
        client.close();//from w  w  w.j a  va  2  s  .  c o  m
        MongoTemplate t = (MongoTemplate) options;
        DB db = t.getDb();
        if (db != null) {
            Mongo m = db.getMongo();
            if (m != null) {
                m.close();
            }
        }
    }
}

From source file:com.hangum.tadpole.mongodb.core.test.ConAndAuthentication.java

License:Open Source License

/**
 * db  ? //ww w .ja  v  a  2 s  . c  o m
 * 
 * @param args
 */
public static void main(String[] args) {
    ConAndAuthentication testMongoCls = new ConAndAuthentication();

    Mongo mongo = testMongoCls.connection(serverurl, port);
    if (mongo != null) {
        DB testDB = mongo.getDB("test");
        // Set<String> collectionNames =
        // testMongoCls.getCollectionNames(testDB);
        // for (String collection : collectionNames) {
        testMongoCls.getCollectionInfo(testDB, "store");
        // }
    }
    mongo.close();
}

From source file:com.hangum.tadpole.mongodb.core.test.MongoTestAddUsers.java

License:Open Source License

/**
 * @param args//w w  w .  j  av a2s  .  c o  m
 */
public static void main(String[] args) throws Exception {
    ConAndAuthentication testMongoCls = new ConAndAuthentication();
    Mongo mongo = testMongoCls.connection(ConAndAuthentication.serverurl, ConAndAuthentication.port);
    DB db = mongo.getDB("test");

    boolean bool = db.authenticate("admin", "admin".toCharArray());
    System.out.println(bool);

    //      WriteResult wr = db.addUser("admin", "admin".toCharArray());
    //      System.out.println("[add user]" +  wr.getError() );

    //      CommandResult cr = db.getStats();
    //         
    //      System.out.println("[ok]" + cr.ok() );
    //      if(!cr.ok()) System.out.println("[Exception ]" + cr.getException().toString());
    //      System.out.println("[toString]" + JSONUtil.getPretty(cr.toString()));
    //      System.out.println("[size]" + cr.size() );

    mongo.close();
}

From source file:com.hangum.tadpole.mongodb.core.test.MongoTestAndORComplexStmt.java

License:Open Source License

/**
 * @param args/*from  w w  w  . j av  a 2 s.  co  m*/
 */
public static void main(String[] args) throws Exception {
    ConAndAuthentication testMongoCls = new ConAndAuthentication();
    Mongo mongo = testMongoCls.connection(ConAndAuthentication.serverurl, ConAndAuthentication.port);
    DB db = mongo.getDB("test");

    DBCollection myColl = db.getCollection("rental");

    BasicDBObject mainQuery = new BasicDBObject();

    // tmp and
    BasicDBObject tmpAndQuery = new BasicDBObject();
    tmpAndQuery.append("inventory_id", 100);
    tmpAndQuery.append("rental_id", new BasicDBObject("$ne", 1));

    mainQuery.put("$and", tmpAndQuery);

    // tmp or
    ArrayList<BasicDBObject> myList = new ArrayList<BasicDBObject>();
    myList.add(new BasicDBObject("customer_id", 3));

    mainQuery.put("$or", myList);

    System.out.println(mainQuery.toString());

    DBCursor myCursor = myColl.find(mainQuery);
    System.out.println("[result cursor size is " + myCursor.count());
    while (myCursor.hasNext()) {
        System.out.println(myCursor.next());
    }

    mongo.close();
}

From source file:com.hangum.tadpole.mongodb.core.test.MongoTestAndStmt.java

License:Open Source License

/**
 * @param args/*from w w w .  j ava  2  s  .  co m*/
 */
public static void main(String[] args) throws Exception {
    ConAndAuthentication testMongoCls = new ConAndAuthentication();
    Mongo mongo = testMongoCls.connection(ConAndAuthentication.serverurl, ConAndAuthentication.port);
    DB db = mongo.getDB("test");

    DBCollection myColl = db.getCollection("city1");

    // show column
    BasicDBObject myColumn = new BasicDBObject();
    myColumn.put("loc.y", true);

    // where
    BasicDBObject myAndQuery = new BasicDBObject();
    //      myAndQuery.append("rental_id", new BasicDBObject("$gte", 1));
    //      myAndQuery.append("inventory_id", 367);//new BasicDBObject("$eq", 367));

    DBCursor myCursor = myColl.find(myAndQuery, myColumn);
    while (myCursor.hasNext()) {
        System.out.println(myCursor.next());
    }

    mongo.close();
}

From source file:com.hangum.tadpole.mongodb.core.test.MongoTestCreateDB.java

License:Open Source License

/**
 * @param args/*from ww w. j  a va  2  s . c o m*/
 */
public static void main(String[] args) throws Exception {
    ConAndAuthentication testMongoCls = new ConAndAuthentication();
    Mongo mongo = testMongoCls.connection(ConAndAuthentication.serverurl, ConAndAuthentication.port);
    DB db = mongo.getDB("newdb2");
    Set<String> listColNames = db.getCollectionNames();
    for (String string : args) {
        System.out.println("[collection name]" + string);
    }

    //      DBObject dbObject = (DBObject) JSON.parse("{capped:true, size:100000}");
    //      db.createCollection("test", dbObject);

    mongo.close();
}

From source file:com.hangum.tadpole.mongodb.core.test.MongoTestCurrentOp.java

License:Open Source License

/**
 * @param args//  ww  w.j av a2  s  .c  om
 */
public static void main(String[] args) throws Exception {
    ConAndAuthentication testMongoCls = new ConAndAuthentication();
    Mongo mongo = testMongoCls.connection(ConAndAuthentication.serverurl, ConAndAuthentication.port);
    DB db = mongo.getDB("test");

    DBObject dbObj = (DBObject) db.eval("db.currentOp()");
    System.out.println(JSONUtil.getPretty(dbObj.toString()));

    BasicDBList dbInprogs = (BasicDBList) dbObj.get("inprog");
    for (Object object : dbInprogs) {
        BasicDBObject obj = (BasicDBObject) object;
        System.out.println("[opid]" + obj.get("opid"));

        //         System.out.println("##[start] killOp##############");
        //         db.eval("db.killOp(" + obj.get("opid") + ")");
        //         System.out.println("##[stop] killOp##############");
    }

    mongo.close();
}

From source file:com.hangum.tadpole.mongodb.core.test.MongoTestDBStats.java

License:Open Source License

/**
 * @param args// w w  w. j a  v a2 s.  c  om
 */
public static void main(String[] args) throws Exception {
    ConAndAuthentication testMongoCls = new ConAndAuthentication();
    Mongo mongo = testMongoCls.connection(ConAndAuthentication.serverurl, ConAndAuthentication.port);
    DB db = mongo.getDB("test");

    CommandResult cr = db.getStats();

    System.out.println("[ok]" + cr.ok());
    if (!cr.ok())
        System.out.println("[Exception ]" + cr.getException().toString());
    System.out.println("[toString]" + JSONUtil.getPretty(cr.toString()));
    System.out.println("[size]" + cr.size());

    mongo.close();
}

From source file:com.hangum.tadpole.mongodb.core.test.MongoTestGridFS.java

License:Open Source License

/**
 * @param args/*w  ww. j ava  2  s.  c  o m*/
 */
public static void main(String[] args) throws Exception {
    ConAndAuthentication testMongoCls = new ConAndAuthentication();
    Mongo mongo = testMongoCls.connection(ConAndAuthentication.serverurl, ConAndAuthentication.port);
    DB db = mongo.getDB("test");

    //      saveImage(db);
    //      getImage(db);
    allList(db);

    mongo.close();
}