Java Code Examples for com.mongodb.DB.createCollection()

The following are Jave code examples for showing how to use createCollection() of the com.mongodb.DB class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: mongodb-broker   File:   View Source Code Vote up 6 votes
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");
			// drop the collection so the db is empty
//			col.drop();
			return db; 
		} catch (MongoException e) {
			// try to clean up and fail
			try {
			} catch (MongoServiceException ignore) {}
			throw handleException(e);
Example 2
Project: hadoop-mini-clusters   File:   View Source Code Vote up 6 votes
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()); BasicDBObject("testDoc", new Date()));"MONGODB: Number of items in collection: {}", col.count());
    assertEquals(1, col.count());
    DBCursor cursor = col.find();
    while(cursor.hasNext()) {"MONGODB: Document output: {}",;
Example 3
Project: xxl-incubator   File:   View Source Code Vote up 5 votes
 * 新增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;
Example 4
Project: spring-cloud-stream-app-starters   File:   View Source Code Vote up 5 votes
public void setUp() {
	DB db = mongo.getDB("test");
	DBCollection col = db.createCollection("testing", new BasicDBObject()); BasicDBObject("greeting", "hello")); BasicDBObject("greeting", "hola"));