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


Java Mongo类代码示例

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


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

示例1: getEstimatedSizeBytes

import com.mongodb.Mongo; //导入依赖的package包/类
@Override
public long getEstimatedSizeBytes(PipelineOptions options) throws Exception {
  Mongo mongo = spec.connectionConfiguration().setupMongo();
  try {
    GridFS gridfs = spec.connectionConfiguration().setupGridFS(mongo);
    DBCursor cursor = createCursor(gridfs);
    long size = 0;
    while (cursor.hasNext()) {
      GridFSDBFile file = (GridFSDBFile) cursor.next();
      size += file.getLength();
    }
    return size;
  } finally {
    mongo.close();
  }
}
 
开发者ID:apache,项目名称:beam,代码行数:17,代码来源:MongoDbGridFSIO.java

示例2: NaviMongoListDriver

import com.mongodb.Mongo; //导入依赖的package包/类
public NaviMongoListDriver(ServerUrlUtil.ServerUrl server, String auth, NaviPoolConfig poolConfig) throws NumberFormatException, MongoException, UnknownHostException {
    super(server, auth, poolConfig);

    String masterUrl = null;
    if (server.getHost() != null && server.getPort() != 0)
        masterUrl = server.getHost() + ":" + server.getPort();
    List<ServerAddress> addresslist = new ArrayList<>();
    // 找到master
    List<String> listHostPorts = new ArrayList<>();
    String[] hostPorts = server.getUrl().split(",");
    Collections.addAll(listHostPorts, hostPorts);
    for (int i = 0; i < listHostPorts.size(); i++) {
        if (listHostPorts.get(0).equals(masterUrl))
            break;
        listHostPorts.add(listHostPorts.remove(0));
    }
    for (String hostPort : listHostPorts) {
        addresslist.add(new ServerAddress(hostPort));
    }

    mongo = new Mongo(addresslist, getMongoOptions(poolConfig));
    // mongo.setReadPreference(ReadPreference.SECONDARY);

    startIdleConnCheck();
}
 
开发者ID:sunguangran,项目名称:navi,代码行数:26,代码来源:NaviMongoListDriver.java

示例3: getMongo

import com.mongodb.Mongo; //导入依赖的package包/类
public Mongo getMongo() {
      if (isClose()) {
          throw new NaviSystemException("the driver has been closed!",
              NaviError.SYSERROR);
      }
      /*
      try {
	log.info("get mongo is open:" + mongo.getConnector().isOpen());
	// int count = mongo.getConnector().getDBPortPool(new
	// ServerAddress(server.getHost(), server.getPort())).available();
	// log.info("get mongo available:" + count);
	log.info("getConnectPoint:"
			+ mongo.getConnector().getConnectPoint());
} catch (Exception e) {
	// TODO Auto-generated catch block
	// UnknownHostException
	e.printStackTrace();
}
*/
      return mongo;
  }
 
开发者ID:sunguangran,项目名称:navi,代码行数:22,代码来源:NaviMongoListDriver.java

示例4: mongo

import com.mongodb.Mongo; //导入依赖的package包/类
@Override
public Mongo mongo() throws Exception {
    final MongoCredential credential = MongoCredential.createCredential(
            mongoClientUri().getUsername(),
            getDatabaseName(),
            mongoClientUri().getPassword());

    final String hostUri = mongoClientUri().getHosts().get(0);
    final String[] host = hostUri.split(":");
    return new MongoClient(new ServerAddress(
            host[0], host.length > 1 ? Integer.parseInt(host[1]) : DEFAULT_PORT),
            Collections.singletonList(credential),
            mongoClientOptions());
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:15,代码来源:MongoDbCloudConfigBootstrapConfiguration.java

示例5: newMongoDbClient

import com.mongodb.Mongo; //导入依赖的package包/类
/**
 * New mongo db client.
 *
 * @param mongo the mongo
 * @return the mongo
 */
public static Mongo newMongoDbClient(final AbstractMongoInstanceProperties mongo) {
    return new MongoClient(new ServerAddress(
            mongo.getHost(),
            mongo.getPort()),
            Collections.singletonList(
                    MongoCredential.createCredential(
                            mongo.getUserId(),
                            mongo.getDatabaseName(),
                            mongo.getPassword().toCharArray())),
            newMongoDbClientOptions(mongo));
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:18,代码来源:Beans.java

示例6: mongo

import com.mongodb.Mongo; //导入依赖的package包/类
@Override
@Bean(destroyMethod = "close")
public Mongo mongo() throws Exception {
    return new EmbeddedMongoBuilder()
        .version("3.4.2")
        .build();
}
 
开发者ID:BakkerTom,项目名称:happy-news,代码行数:8,代码来源:TestConfig.java

示例7: mongo

import com.mongodb.Mongo; //导入依赖的package包/类
/**
 * @return A new in memory MongoDB.
 */
@Bean(destroyMethod = "close")
public static Mongo mongo() throws IOException {
    return new EmbeddedMongoBuilder()
        .version("2.4.5")
        .bindIp("127.0.0.1")
        .port(12345)
        .build();
}
 
开发者ID:BakkerTom,项目名称:happy-news,代码行数:12,代码来源:TwitterCrawlerTest.java

示例8: getMongo

import com.mongodb.Mongo; //导入依赖的package包/类
private Mongo getMongo(MongoClientURI mongoURI) {
    try {
        Mongo mongo = new MongoClient(mongoURI);
        activityMongos.add(mongo);

        return mongo;
    } catch (UnknownHostException e) {
        throw new CannotGetMongoDbConnectionException(String.format("con't get mongo '%s' connection!", mongoURI.getHosts()));
    }
}
 
开发者ID:lodsve,项目名称:lodsve-framework,代码行数:11,代码来源:DynamicMongoConnection.java

示例9: destroy

import com.mongodb.Mongo; //导入依赖的package包/类
@Override
public void destroy() throws Exception {
    if (!CollectionUtils.isEmpty(activityMongos)) {
        for (Mongo mongo : activityMongos) {
            mongo.close();
        }
    }
}
 
开发者ID:lodsve,项目名称:lodsve-framework,代码行数:9,代码来源:DynamicMongoConnection.java

示例10: mongo

import com.mongodb.Mongo; //导入依赖的package包/类
@SuppressWarnings("deprecation")
@Override
public Mongo mongo() {
	try {
		return new Mongo("mongodb://localhost/cityoffice");
	} catch (UnknownHostException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	return null;
}
 
开发者ID:denis-rodionov,项目名称:cityoffice,代码行数:12,代码来源:DevelopmentConfiguration.java

示例11: mongo

import com.mongodb.Mongo; //导入依赖的package包/类
@Override
public Mongo mongo() throws Exception {
    /**
     *
     * this is for a single db
     */

    return new MongoClient();
}
 
开发者ID:denis-rodionov,项目名称:cityoffice,代码行数:10,代码来源:RealDatabaseTestConfiguration.java

示例12: mongo

import com.mongodb.Mongo; //导入依赖的package包/类
@Override
public
@Bean
Mongo mongo() {
  // uses fongo for in-memory tests
  return new Fongo("integration-test").getMongo();
}
 
开发者ID:hollannikas,项目名称:ssoidh,代码行数:8,代码来源:ITMongoConfiguration.java

示例13: mongo

import com.mongodb.Mongo; //导入依赖的package包/类
@Override
@Bean
public Mongo mongo() throws Exception {
    if (username != null && password != null && username.length() > 0) {
        ServerAddress address = new ServerAddress(mongoHost, mongoPort);
        MongoCredential credential = MongoCredential.createCredential(username, mongoDatabasename, password.toCharArray());
        List<MongoCredential> credentials = new ArrayList<>();
        credentials.add(credential);
        return new MongoClient(address, credentials);
    }
    return new MongoClient(mongoHost, mongoPort);
}
 
开发者ID:Orange-OpenSource,项目名称:fiware-openlpwa-iotagent,代码行数:13,代码来源:MongoConfiguration.java

示例14: mongo

import com.mongodb.Mongo; //导入依赖的package包/类
@Override
public Mongo mongo() throws Exception {
    if(!authenticate) {
        //Allows testing with a database without users and authentication configured.
        //should not be used in production.
        log.warn("MongoDB is accessed without any authentication. " +
                "This is strongly discouraged and should only be used in a testing environment.");
        return new MongoClient(hostname);
    } else {
        List<MongoCredential> cred = new LinkedList<>();
        cred.add(MongoCredential.createCredential(dbUserName, dbAuthDB, dbPasswd.toCharArray()));
        ServerAddress addr = new ServerAddress(hostname, dbPort);
        return new MongoClient(addr, cred);
    }
}
 
开发者ID:Morbrolhc,项目名称:kanbanboard,代码行数:16,代码来源:SpringMongoConfig.java

示例15: mongo

import com.mongodb.Mongo; //导入依赖的package包/类
@Override
public Mongo mongo() throws Exception {
    if (!StringUtils.isEmpty(getUsername()) && !StringUtils.isEmpty(getPassword())) {
        try {
            MongoCredential credential = MongoCredential.createCredential(getUsername(), getDatabaseName(), getPassword().toCharArray());
            return new MongoClient(hostname, Collections.singletonList(credential));
        } catch (Exception e) {
            return new MongoClient(hostname);
        }
    } else {
        return new MongoClient(hostname);
    }

}
 
开发者ID:KonkerLabs,项目名称:konker-platform,代码行数:15,代码来源:MongoConfig.java


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