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


Java MongoCollection.createIndex方法代码示例

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


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

示例1: createDbAndCollections

import com.mongodb.client.MongoCollection; //导入方法依赖的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

示例2: ensureIndex

import com.mongodb.client.MongoCollection; //导入方法依赖的package包/类
@Override
public void ensureIndex(MongoCollection<Document> collection, String name, Document index, IndexOptions opts, boolean replace) {
	
	if(replace){
		collection.dropIndex(name);
	}
			
	collection.createIndex(index, opts);
}
 
开发者ID:wesley-ramos,项目名称:spring-multitenancy,代码行数:10,代码来源:MongoBasicOperations.java

示例3: ensureIndexes

import com.mongodb.client.MongoCollection; //导入方法依赖的package包/类
private void ensureIndexes(String suffix) {
    MongoCollection index = db.getCollection("index_" + suffix);
    index.createIndex(new Document(Field.millis, 1));
    index.createIndex(new Document(Field.call_id, "hashed"));
    index.createIndex(new Document(Field.caller, "hashed"));
    index.createIndex(new Document(Field.callee, "hashed"));

    MongoCollection raw = db.getCollection("raw_" + suffix);
    raw.createIndex(new Document(Field.call_id, "hashed"));
}
 
开发者ID:sip3io,项目名称:tapir,代码行数:11,代码来源:SipMessageMongoCron.java

示例4: indexCollection

import com.mongodb.client.MongoCollection; //导入方法依赖的package包/类
public void indexCollection(final String collectionName, final String field) {
    // Sanity checks
    if (StringUtils.isEmpty(collectionName)) {
        throw new IllegalArgumentException("count :: Collection name should not be blank");
    }

    // Collection
    MongoCollection<Document> collection = this.database.getCollection(collectionName);
    collection.createIndex(Indexes.descending(field));
}
 
开发者ID:millij,项目名称:osm-processor,代码行数:11,代码来源:MongoStore.java

示例5: createIndex

import com.mongodb.client.MongoCollection; //导入方法依赖的package包/类
/**
 * 创建索引
 *
 * @param collectionName 集合
 * @param indexName      索引名
 * @param keys           键信息,如 securityCode:1
 * @param isUnique       是否唯一索引
 */
public void createIndex(String collectionName, String indexName, Map<String, Integer> keys, boolean isUnique) {
    MongoCollection collection = sMongoDatabase.getCollection(collectionName);
    IndexOptions indexOptions = new IndexOptions();
    indexOptions.background(true);
    indexOptions.unique(isUnique);
    indexOptions.name(indexName);
    Map<String, Object> keyIndexs = new HashMap<>(16);
    for (Map.Entry<String, Integer> entry : keys.entrySet()) {
        keyIndexs.put(entry.getKey(), entry.getValue() > 0 ? 1 : entry.getValue() == 0 ? 0 : -1);
    }
    collection.createIndex(new Document(keyIndexs), indexOptions);
}
 
开发者ID:wxz1211,项目名称:dooo,代码行数:21,代码来源:MongodbDataAccess.java

示例6: testKeepIndexOutsideNamespace

import com.mongodb.client.MongoCollection; //导入方法依赖的package包/类
@Test
public void testKeepIndexOutsideNamespace() throws Exception {
    TestRunner runner = TestRunners.newTestRunner(new StoreInMongo());
    addMongoService(runner);
    MongoCollection<Document> collection = mongo.getMongoClient().getDatabase(MONGO_DATABASE_NAME).getCollection("index_test");
    Document index = new Document().append("_id", "hashed");
    collection.createIndex(index);
    runner.setProperty(MongoProps.DATABASE, MONGO_DATABASE_NAME);
    runner.setProperty(MongoProps.COLLECTION, "index_test");
    runner.assertValid();
    runner.run();
    Set<String> indexNames = AbstractMongoProcessor.getIndexNames(collection);
    String normalizedIndexName = AbstractMongoProcessor.normalizeIndexName("", index.toJson());
    assertTrue(indexNames.contains(normalizedIndexName));
}
 
开发者ID:Asymmetrik,项目名称:nifi-nars,代码行数:16,代码来源:StoreInMongoIT.java

示例7: createIndex

import com.mongodb.client.MongoCollection; //导入方法依赖的package包/类
protected void createIndex(String name, BasicDBList dbList, MongoCollection<Document> collection) {
    if (dbList.isEmpty() || name == null) {
        return;
    }

    BasicDBObject index = (BasicDBObject) dbList.get(0);
    IndexOptions options = new IndexOptions().name(name);
    if (dbList.size() > 1) {
        BasicDBObject opts = (BasicDBObject) dbList.get(1);
        if (opts.get("unique") != null && opts.get("unique") instanceof Boolean) {
            options = options.unique(opts.getBoolean("unique"));
        }
        if (opts.get("expireAfterSeconds") != null && opts.get("expireAfterSeconds") instanceof Integer) {
            options = options.expireAfter(Long.valueOf(opts.getInt("expireAfterSeconds")), TimeUnit.SECONDS);
        }
        if (opts.get("background") != null && opts.get("background") instanceof Boolean) {
            options = options.background(opts.getBoolean("background"));
        }
        if (opts.get("bits") != null && opts.get("bits") instanceof Integer) {
            options = options.bits(opts.getInt("bits"));
        }
        if (opts.get("bucketSize") != null && opts.get("bucketSize") instanceof Double) {
            options = options.bucketSize(opts.getDouble("bucketSize"));
        }
        if (opts.get("defaultLanguage") != null && opts.get("defaultLanguage") instanceof String) {
            options = options.defaultLanguage(opts.getString("defaultLanguage"));
        }
        if (opts.get("languageOverride") != null && opts.get("languageOverride") instanceof String) {
            options = options.languageOverride(opts.getString("languageOverride"));
        }
        if (opts.get("min") != null && opts.get("min") instanceof Double) {
            options = options.min(opts.getDouble("min"));
        }
        if (opts.get("max") != null && opts.get("max") instanceof Double) {
            options = options.max(opts.getDouble("max"));
        }
        if (opts.get("sparse") != null && opts.get("sparse") instanceof Boolean) {
            options = options.sparse(opts.getBoolean("sparse"));
        }
        if (opts.get("textVersion") != null && opts.get("textVersion") instanceof Integer) {
            options = options.textVersion(opts.getInt("textVersion"));
        }
        if (opts.get("version") != null && opts.get("version") instanceof Integer) {
            options = options.version(opts.getInt("version"));
        }
        if (opts.get("weights") != null && opts.get("weights") instanceof Bson) {
            options = options.weights((Bson) opts.get("weights"));
        }
    }
    collection.createIndex(new Document(index), options);
}
 
开发者ID:Asymmetrik,项目名称:nifi-nars,代码行数:52,代码来源:AbstractMongoProcessor.java


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