本文整理汇总了Java中com.mongodb.DB.createCollection方法的典型用法代码示例。如果您正苦于以下问题:Java DB.createCollection方法的具体用法?Java DB.createCollection怎么用?Java DB.createCollection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.mongodb.DB
的用法示例。
在下文中一共展示了DB.createCollection方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createDatabase
import com.mongodb.DB; //导入方法依赖的package包/类
public DB createDatabase(String databaseName) throws MongoServiceException {
try {
DB db = client.getDB(databaseName);
// save into a collection to force DB creation.
DBCollection col = db.createCollection("foo", null);
BasicDBObject obj = new BasicDBObject();
obj.put("foo", "bar");
col.insert(obj);
// drop the collection so the db is empty
// col.drop();
return db;
} catch (MongoException e) {
// try to clean up and fail
try {
deleteDatabase(databaseName);
} catch (MongoServiceException ignore) {}
throw handleException(e);
}
}
示例2: testMongodbLocalServer
import com.mongodb.DB; //导入方法依赖的package包/类
@Test
public void testMongodbLocalServer() throws Exception {
MongoClient mongo = new MongoClient(mongodbLocalServer.getIp(), mongodbLocalServer.getPort());
DB db = mongo.getDB(propertyParser.getProperty(ConfigVars.MONGO_DATABASE_NAME_KEY));
DBCollection col = db.createCollection(propertyParser.getProperty(ConfigVars.MONGO_COLLECTION_NAME_KEY),
new BasicDBObject());
col.save(new BasicDBObject("testDoc", new Date()));
LOG.info("MONGODB: Number of items in collection: {}", col.count());
assertEquals(1, col.count());
DBCursor cursor = col.find();
while(cursor.hasNext()) {
LOG.info("MONGODB: Document output: {}", cursor.next());
}
cursor.close();
}
示例3: addCollection
import com.mongodb.DB; //导入方法依赖的package包/类
/**
* 新增DBCollection对象 = 表
* @param dbName
* @param collName
* @param options
* @return
*/
public static DBCollection addCollection(String dbName, String collName, DBObject options) {
DB db = getDB(dbName);
if (db != null) {
DBCollection collection = db.createCollection(collName, options);
return collection;
}
return null;
}
示例4: setUp
import com.mongodb.DB; //导入方法依赖的package包/类
@Before
public void setUp() {
DB db = mongo.getDB("test");
DBCollection col = db.createCollection("testing", new BasicDBObject());
col.save(new BasicDBObject("greeting", "hello"));
col.save(new BasicDBObject("greeting", "hola"));
}
开发者ID:spring-cloud,项目名称:spring-cloud-stream-app-starters,代码行数:8,代码来源:MongodbSourceApplicationTests.java