當前位置: 首頁>>代碼示例>>Java>>正文


Java MongoDatabase.createCollection方法代碼示例

本文整理匯總了Java中com.mongodb.client.MongoDatabase.createCollection方法的典型用法代碼示例。如果您正苦於以下問題:Java MongoDatabase.createCollection方法的具體用法?Java MongoDatabase.createCollection怎麽用?Java MongoDatabase.createCollection使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.mongodb.client.MongoDatabase的用法示例。


在下文中一共展示了MongoDatabase.createCollection方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: initCollections

import com.mongodb.client.MongoDatabase; //導入方法依賴的package包/類
private static void initCollections(MongoDatabase db) {
    try {
        db.createCollection("users");
        db.createCollection("categories");
        db.createCollection("feeds");
        db.createCollection("licenses");
    } catch (Exception e) {
        Log.w(TAG, "[attemptCreateCollections] " + e.getMessage());
    }
    users = db.getCollection("users");
    categories = db.getCollection("categories");
    feeds = db.getCollection("feeds");
    licenses = db.getCollection("licenses");

    users.createIndex(
        Indexes.ascending(User.USERNAME),
        new IndexOptions().unique(true));

    categories.createIndex(
        Indexes.ascending(Category.OWNER, Category.KEY),
        new IndexOptions().unique(true));
}
 
開發者ID:drakeet,項目名稱:rebase-server,代碼行數:23,代碼來源:MongoDBs.java

示例2: getCollectionList

import com.mongodb.client.MongoDatabase; //導入方法依賴的package包/類
public HashMap<String, MongoCollection> getCollectionList(MongoDatabase mongoDatabase) {
    HashMap<String, MongoCollection> dbCollectionList = new HashMap<String, MongoCollection>();
    String[] tableNameList = {athenaFeatureField.ERROR_MSG, athenaFeatureField.FLOW_REMOVED, athenaFeatureField.PACKET_IN,
            athenaFeatureField.PORT_STATUS, athenaFeatureField.FLOW_STATS, athenaFeatureField.QUEUE_STATS,
            athenaFeatureField.AGGREGATE_STATS, athenaFeatureField.TABLE_STATS, athenaFeatureField.PORT_STATS, "terabyte"};
    String teraBytes = "terabyte";

    for (String tableName : tableNameList) {
        MongoCollection dbCollection = mongoDatabase.getCollection(tableName);
        if (dbCollection == null) {
            mongoDatabase.createCollection(tableName);
            dbCollection = mongoDatabase.getCollection(tableName);
        }
        dbCollectionList.put(tableName, dbCollection);
    }

    return dbCollectionList;
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:19,代碼來源:ReplicateDatabaseData.java

示例3: getCollectionList

import com.mongodb.client.MongoDatabase; //導入方法依賴的package包/類
public HashMap<String, MongoCollection> getCollectionList(MongoDatabase mongoDatabase) {
    HashMap<String, MongoCollection> dbCollectionList = new HashMap<String, MongoCollection>();
    String[] tableNameList = {AthenaFeatureField.ERROR_MSG, AthenaFeatureField.FLOW_REMOVED,
            AthenaFeatureField.PACKET_IN,
            AthenaFeatureField.PORT_STATUS, AthenaFeatureField.FLOW_STATS, AthenaFeatureField.QUEUE_STATS,
            AthenaFeatureField.AGGREGATE_STATS, AthenaFeatureField.TABLE_STATS, AthenaFeatureField.PORT_STATS};

    for (String tableName : tableNameList) {
        MongoCollection dbCollection = mongoDatabase.getCollection(tableName);
        if (dbCollection == null) {
            mongoDatabase.createCollection(tableName);
            dbCollection = mongoDatabase.getCollection(tableName);
        }
        dbCollectionList.put(tableName, dbCollection);
    }

    return dbCollectionList;
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:19,代碼來源:FeatureDatabaseMgmtManager.java

示例4: createDbAndCollections

import com.mongodb.client.MongoDatabase; //導入方法依賴的package包/類
private static void createDbAndCollections(String dbName,
    String collectionName, String indexFieldName) {
  MongoDatabase db = mongoClient.getDatabase(dbName);
  MongoCollection<Document> mongoCollection = db
      .getCollection(collectionName);
  if (mongoCollection == null) {
    db.createCollection(collectionName);
    mongoCollection = db.getCollection(collectionName);
  }
  IndexOptions indexOptions = new IndexOptions().unique(true)
      .background(false).name(indexFieldName);
  Bson keys = new Document(indexFieldName, Integer.valueOf(1));
  mongoCollection.createIndex(keys, indexOptions);
}
 
開發者ID:skhalifa,項目名稱:QDrill,代碼行數:15,代碼來源:MongoTestSuit.java

示例5: should_return_that_the_collection_exists_in_the_database

import com.mongodb.client.MongoDatabase; //導入方法依賴的package包/類
@Test public void
should_return_that_the_collection_exists_in_the_database(){
	String collectionName = "collection_registered_in_database";
	
	MongoDatabase database =  mongoEmbedded.getDatabase();	
	database.createCollection(collectionName);
	
	MongoPersistentEntityIndex index = Mockito.mock(MongoPersistentEntityIndex.class);
	MongoDataSource dataSource = Mockito.mock(MongoDataSource.class);
	when(dataSource.getDataSource()).thenReturn(database);
	
	MongoBasicOperations operation = new MongoBasicOperations(dataSource, index);
	
	Assert.assertTrue("The 'exist' method returned the incorrect value", operation.exist(collectionName));
}
 
開發者ID:wesley-ramos,項目名稱:spring-multitenancy,代碼行數:16,代碼來源:MongoBasicOperationsTest.java

示例6: start

import com.mongodb.client.MongoDatabase; //導入方法依賴的package包/類
public void start(final int port) {
    MongodStarter starter = MongodStarter.getDefaultInstance();

    try {
        IMongodConfig mongodConfig = new MongodConfigBuilder()
                .version(Version.Main.PRODUCTION)
                .net(new Net(port, Network.localhostIsIPv6()))
                .build();

        mongodExecutable = starter.prepare(mongodConfig);
        mongodExecutable.start();

        // populate
        final MongoClient mongo = new MongoClient("localhost", port);
        final MongoDatabase db = mongo.getDatabase("users");
        db.createCollection("users");
        final MongoCollection<Document> collection = db.getCollection("users");
        final PasswordEncoder encoder = new BasicSaltedSha512PasswordEncoder(SALT);
        final String password = encoder.encode(PASSWORD);
        Map<String, Object> properties1 = new HashMap<>();
        properties1.put(USERNAME, GOOD_USERNAME);
        properties1.put(PASSWORD, password);
        properties1.put(FIRSTNAME, FIRSTNAME_VALUE);
        collection.insertOne(new Document(properties1));
        Map<String, Object> properties2 = new HashMap<>();
        properties2.put(USERNAME, MULTIPLE_USERNAME);
        properties2.put(PASSWORD, password);
        collection.insertOne(new Document(properties2));
        Map<String, Object> properties3 = new HashMap<>();
        properties3.put(USERNAME, MULTIPLE_USERNAME);
        properties3.put(PASSWORD, password);
        collection.insertOne(new Document(properties3));

    } catch (final IOException e) {
        throw new RuntimeException(e);
    }
}
 
開發者ID:yaochi,項目名稱:pac4j-plus,代碼行數:38,代碼來源:MongoServer.java


注:本文中的com.mongodb.client.MongoDatabase.createCollection方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。