当前位置: 首页>>代码示例>>Java>>正文


Java Mongo.getDB方法代码示例

本文整理汇总了Java中com.mongodb.Mongo.getDB方法的典型用法代码示例。如果您正苦于以下问题:Java Mongo.getDB方法的具体用法?Java Mongo.getDB怎么用?Java Mongo.getDB使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.mongodb.Mongo的用法示例。


在下文中一共展示了Mongo.getDB方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: MongoLog

import com.mongodb.Mongo; //导入方法依赖的package包/类
public MongoLog( String sessionID, String dbName ) throws UnknownHostException {
    mongo = new Mongo( HOST_IP_ADDRESS, PORT );

    // All sessions are stored in the same DB.  Having a separate DB for
    // each uses an excessive amount of disk space.
    DB database = mongo.getDB( dbName );

    // Authenticate.
    try {
        boolean auth = database.authenticate( "phetsimclient", ( MER + SimSharingManager.MONGO_PASSWORD + "" + ( 2 * 2 * 2 ) + "ss0O88723otbubaoue" ).toCharArray() );
        if ( !auth ) {
            new RuntimeException( "Authentication failed" ).printStackTrace();
        }
    }

    //A MongoException.Network indicates a failure to reach mongo for the authentication attempt, and hence there is probably no internet connection.  See #3304
    catch ( MongoException.Network exception ) {
        LOGGER.warning( "Failed to connect to mongo during authentication.  Perhaps there is no internet connection." );
    }

    //One collection per session, lets us easily iterate and add messages per session.
    collection = database.getCollection( sessionID );

    /*
     * Mongo logs entire stack traces when failure occur, which is incredibly annoying.
     * Turn off Mongo logging here by interrogating the LogManager.
     * Do this at the end of the constructor, so that Mongo loggers have been instantiated.
     */
    LOGGER.info( "turning off MongoDB loggers" );
    Enumeration<String> names = LogManager.getLogManager().getLoggerNames();
    while ( names.hasMoreElements() ) {
        String name = names.nextElement();
        if ( name.startsWith( "com.mongodb" ) ) {
            LogManager.getLogManager().getLogger( name ).setLevel( Level.OFF );
        }
    }
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:38,代码来源:MongoLog.java

示例2: main

import com.mongodb.Mongo; //导入方法依赖的package包/类
public static void main( String[] args ) throws UnknownHostException {
    Mongo m = new Mongo( MongoLog.HOST_IP_ADDRESS, MongoLog.PORT );
    DB db = m.getDB( MongoLoadTester.LOAD_TESTING_DB_NAME );
    boolean authenticated = db.authenticate( MongoLoadTester.DB_USER_NAME,
                                             ( MongoLoadTester.MER + SimSharingManager.MONGO_PASSWORD + "" + ( 2 * 2 * 2 ) + "ss0O88723otbubaoue" ).toCharArray() );

    System.out.println( "authenticated = " + authenticated );
    if ( !authenticated ) {
        System.out.println( "Authentication failed, aborting test." );
        return;
    }
    DBCollection collection = db.getCollection( MongoLoadTester.DB_COLLECTION );
    long count = collection.getCount();
    System.out.println( "count = " + count );
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:16,代码来源:MongoLoadTesterReader.java

示例3: getDb

import com.mongodb.Mongo; //导入方法依赖的package包/类
public DB getDb(String dbName) throws DataAccessException {
    Assert.hasText(dbName, "Database name must not be empty.");

    DefaultNaviDataSource defaultDataSource = (DefaultNaviDataSource) dataSource;

    //NaviMongoDriver driver = (NaviMongoDriver) defaultDataSource.getHandle();
    Mongo mongo = (Mongo) defaultDataSource.getHandle().getDriver();
    //DB db = MongoDbUtils.getDB(mongo, dbName, null, null);
    DB db = mongo.getDB(databaseNm);
    if (writeConcern != null) {
        db.setWriteConcern(writeConcern);
    }

    return db;
}
 
开发者ID:sunguangran,项目名称:navi,代码行数:16,代码来源:NaviMongoDbFactory.java

示例4: initialize

import com.mongodb.Mongo; //导入方法依赖的package包/类
/**
 * Do the initialization required to begin providing object store
 * services.
 *
 * <p>The property <tt>"<i>propRoot</i>.odb.mongo.hostport"</tt> should
 * specify the address of the MongoDB server holding the objects.
 *
 * <p>The optional property <tt>"<i>propRoot</i>.odb.mongo.dbname"</tt>
 * allows the Mongo database name to be specified.  If omitted, this
 * defaults to <tt>"elko"</tt>.
 *
 * <p>The optional property <tt>"<i>propRoot</i>.odb.mongo.collname"</tt>
 * allows the collection containing the object repository to be specified.
 * If omitted, this defaults to <tt>"odb"</tt>.
 *
 * @param props  Properties describing configuration information.
 * @param propRoot  Prefix string for selecting relevant properties.
 * @param appTrace  Trace object for use in logging.
 */
public void initialize(BootProperties props, String propRoot,
                       Trace appTrace)
{
    tr = appTrace;
    propRoot = propRoot + ".odb.mongo";

    String addressStr = props.getProperty(propRoot + ".hostport");
    if (addressStr == null) {
        tr.fatalError("no mongo database server address specified");
    }
    int colon = addressStr.indexOf(':');
    int port;
    String host;
    if (colon < 0) {
        port = 27017;
        host = addressStr;
    } else {
        port = Integer.parseInt(addressStr.substring(colon + 1)) ;
        host = addressStr.substring(0, colon);
    }
    //try {
        myMongo = new Mongo(host, port);
    //} catch (UnknownHostException e) {
    //    tr.fatalError("mongodb server " + addressStr + ": unknown host");
    //}
    String dbName = props.getProperty(propRoot + ".dbname", "elko");
    myDB = myMongo.getDB(dbName);

    String collName = props.getProperty(propRoot + ".collname", "odb");
    myODBCollection = myDB.getCollection(collName);
}
 
开发者ID:FUDCo,项目名称:Elko,代码行数:51,代码来源:MongoObjectStore.java

示例5: connectTo

import com.mongodb.Mongo; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
private DB connectTo(final MongoClientURI uri) {
    Mongo mongo = new MongoClient(uri);
    return mongo.getDB(uri.getDatabase());
}
 
开发者ID:ozwolf-software,项目名称:mongo-trek,代码行数:6,代码来源:MongoTrek.java

示例6: setupGridFS

import com.mongodb.Mongo; //导入方法依赖的package包/类
GridFS setupGridFS(Mongo mongo) {
  DB db = database() == null ? mongo.getDB("gridfs") : mongo.getDB(database());
  return bucket() == null ? new GridFS(db) : new GridFS(db, bucket());
}
 
开发者ID:apache,项目名称:beam,代码行数:5,代码来源:MongoDbGridFSIO.java


注:本文中的com.mongodb.Mongo.getDB方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。