• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Indexes类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: initCollections

import com.mongodb.client.model.Indexes; //导入依赖的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: ensureIndexes

import com.mongodb.client.model.Indexes; //导入依赖的package包/类
public static <T extends OkraItem> void ensureIndexes(final Okra<T> okra,
                                                      final MongoClient mongo,
                                                      final String database,
                                                      final String collection) {
    okra.getIndexDefs()
            .stream()
            .map(indexDef -> {
                final boolean ascending = indexDef.getOrdering() == null
                        || indexDef.getOrdering().equals(Ordering.ASC);

                final Bson ordering = ascending
                        ? Indexes.ascending(indexDef.getAttrs()) : Indexes.descending(indexDef.getAttrs());

                return mongo
                        .getDatabase(database)
                        .getCollection(collection)
                        .createIndex(ordering);
            })
            .forEach(indexName -> LOGGER.info("Done. Index name: {}", indexName));
}
 
开发者ID:OkraScheduler,项目名称:OkraSync,代码行数:21,代码来源:IndexCreator.java


示例3: indexCollection

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


示例4: fromSmofIndexField

import com.mongodb.client.model.Indexes; //导入依赖的package包/类
private static Bson fromSmofIndexField(SmofIndexField field) {
 final String fieldName = field.name();
 switch(field.type()) {
 	case ASCENDING:
		return Indexes.ascending(fieldName);
	case DESCENDING:
		return Indexes.descending(fieldName);
	case TEXT:
		return Indexes.text(fieldName);
	}
	handleError(new IllegalArgumentException("Invalid index field."));
	return null;
}
 
开发者ID:JPDSousa,项目名称:mongo-obj-framework,代码行数:14,代码来源:InternalIndex.java


示例5: createRawIndexes

import com.mongodb.client.model.Indexes; //导入依赖的package包/类
private static Set<Bson> createRawIndexes(BsonDocument doc) {
	final Set<Bson> indexes = new LinkedHashSet<>();
	final String name = doc.getString("name").getValue();
	if(name.equals("_id_")) {
		indexes.add(Indexes.ascending(Element.ID));
	}
	else {
		indexes.addAll(parseIndexName(name));
	}
	return indexes;
}
 
开发者ID:JPDSousa,项目名称:mongo-obj-framework,代码行数:12,代码来源:InternalIndex.java


示例6: nextIndex

import com.mongodb.client.model.Indexes; //导入依赖的package包/类
private static Bson nextIndex(StringTokenizer tokens) {
	final Bson index;
	final StringBuilder indexName = new StringBuilder(tokens.nextToken());
	String indexTypeStr = tokens.nextToken();
	IndexType indexT;
	
	while((indexT = IndexType.parse(indexTypeStr)) == null) {
		indexName.append("_").append(indexTypeStr);
		indexTypeStr = tokens.nextToken();
	}
	
	switch(indexT) {
	case ASCENDING:
		index = Indexes.ascending(indexName.toString());
		break;
	case DESCENDING:
		index = Indexes.descending(indexName.toString());
		break;
	case TEXT:
		index = Indexes.text(indexName.toString());
		break;
	default:
		handleError(new IllegalArgumentException("Invalid bson index"));
		index = null;
		break;
	}
	return index;
}
 
开发者ID:JPDSousa,项目名称:mongo-obj-framework,代码行数:29,代码来源:InternalIndex.java


示例7: run

import com.mongodb.client.model.Indexes; //导入依赖的package包/类
@Override
public void run(Environment environment, Namespace namespace, SamConfiguration configuration) throws Exception {

  final MongoDatabase database = configuration.getDbConnectionFactory().getDatabase(environment.lifecycle());

  final MongoCollection<Document> servers = database.getCollection(Collections.SERVERS);
  servers.createIndexes(Lists.newArrayList(
    new IndexModel(
      ascending("fqdn"),
      new IndexOptions().unique(true).sparse(true)
    ),
    new IndexModel(
      compoundIndex(ascending("hostname"), ascending("environment")),
      new IndexOptions().unique(true)
    ),
    new IndexModel(
      compoundIndex(Indexes.text("hostname"), Indexes.text("environment"), Indexes.text("fqdn"), Indexes.text("description")),
      new IndexOptions().weights(new Document().append("hostname", 10).append("fqdn", 10).append("environment", 5)).defaultLanguage("sv")
    )
  ));

  final MongoCollection<Document> applications = database.getCollection(Collections.APPLICATIONS);
  applications.createIndexes(Lists.newArrayList(
    new IndexModel(
      ascending("id"),
      new IndexOptions().unique(true)
    ),
    new IndexModel(
      compoundIndex(Indexes.text("id"), Indexes.text("name"), Indexes.text("description")),
      new IndexOptions().weights(new Document().append("id", 10).append("name", 10)).defaultLanguage("sv")
    )
  ));

  final MongoCollection<Document> groups = database.getCollection(Collections.GROUPS);
  groups.createIndexes(Lists.newArrayList(
    new IndexModel(
      ascending("id"),
      new IndexOptions().unique(true)
    ),
    new IndexModel(
      ascending("tags")
    ),
    new IndexModel(
      compoundIndex(Indexes.text("id"), Indexes.text("name"), Indexes.text("description"), Indexes.text("tags")),
      new IndexOptions().weights(new Document().append("id", 10).append("name", 10).append("tags", 5)).defaultLanguage("sv")
    )
  ));

  final MongoCollection<Document> assets = database.getCollection(Collections.ASSETS);
  assets.createIndexes(Lists.newArrayList(
    new IndexModel(
      ascending("id"),
      new IndexOptions().unique(true)
    ),
    new IndexModel(
      compoundIndex(Indexes.text("id"), Indexes.text("name"), Indexes.text("description")),
      new IndexOptions().weights(new Document().append("id", 10).append("name", 10)).defaultLanguage("sv")
    )
  ));
}
 
开发者ID:atgse,项目名称:sam,代码行数:61,代码来源:CreateDatabaseCommand.java


示例8: createMongoDocIdIndex

import com.mongodb.client.model.Indexes; //导入依赖的package包/类
public static void createMongoDocIdIndex(String collectionName) {
    IndexOptions indexOptions = new IndexOptions().unique(true).background(true);
    MongoCollection<org.bson.Document> collection = mongoClient.getDatabase("mdw").getCollection(collectionName);
    String indexName = collection.createIndex(Indexes.ascending("document_id"), indexOptions);
    LoggerUtil.getStandardLogger().mdwDebug("Created Index : " + indexName + " on collection : " + collectionName);
    collectionDocIdIndexed.putIfAbsent(collectionName, Boolean.valueOf(true));
}
 
开发者ID:CenturyLinkCloud,项目名称:mdw,代码行数:8,代码来源:DatabaseAccess.java


示例9: start

import com.mongodb.client.model.Indexes; //导入依赖的package包/类
@Override
public void start() throws IOException {
  MongoClientURI clientURI = new MongoClientURI(mongoURL);
  client = new MongoClient(clientURI);
  MongoDatabase db = client.getDatabase(clientURI.getDatabase());
  collection = db.getCollection(clientURI.getCollection()).withWriteConcern(WriteConcern.JOURNALED);
  Bson index = Indexes.ascending(pKey);
  collection.createIndex(index);
}
 
开发者ID:axbaretto,项目名称:drill,代码行数:10,代码来源:MongoPersistentStoreProvider.java


示例10: createDbAndCollections

import com.mongodb.client.model.Indexes; //导入依赖的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 = Indexes.ascending(indexFieldName);
  mongoCollection.createIndex(keys, indexOptions);
}
 
开发者ID:axbaretto,项目名称:drill,代码行数:15,代码来源:MongoTestSuit.java


示例11: createIndexes

import com.mongodb.client.model.Indexes; //导入依赖的package包/类
@PostConstruct
public void createIndexes() {

	if (!indexExists(User.class, CUser.email)) {
		this.getCollection(User.class).createIndex(Indexes.ascending(CUser.email),
				new IndexOptions().unique(true));
	}

	if (!indexExists(PersistentLogin.class, CPersistentLogin.userId)) {
		this.getCollection(PersistentLogin.class)
				.createIndex(Indexes.ascending(CPersistentLogin.userId));
	}

}
 
开发者ID:ralscha,项目名称:eds-starter6-mongodb,代码行数:15,代码来源:MongoDb.java


示例12: setUp

import com.mongodb.client.model.Indexes; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
  MongoDatabase db = mongo.getDatabase(DATABASE_NAME);
  db.createCollection(TEST_WRITE_COLLECTION);
  db.createCollection(UNIQUE_KEY_EXCEPTION_COLLECTION);
  testWriteCollection = db.getCollection(TEST_WRITE_COLLECTION);
  testWriteCollection.createIndex(Indexes.text("name"), new IndexOptions().unique(true));
}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:9,代码来源:MongoDBTargetIT.java


示例13: QueryManager

import com.mongodb.client.model.Indexes; //导入依赖的package包/类
public QueryManager(ThreadFactory tf, MongoCollection<Document> db, ReportManager reportManager, I18n i18n, PluginContainer plugin)
{
    this.db = db;
    this.reportManager = reportManager;
    this.i18n = i18n;
    storeExecuter = newSingleThreadExecutor(tf);
    queryShowExecutor = Sponge.getScheduler().createSyncExecutor(plugin);
    this.plugin = plugin;
    db.createIndex(Indexes.hashed("type"));
    db.createIndex(Indexes.descending("date"));
    db.createIndex(Indexes.ascending("data.location.Position_X", "data.location.Position_Z", "data.location.Position_Y"));
    db.createIndex(Indexes.hashed("data.location.WorldUuid"));
}
 
开发者ID:CubeEngine,项目名称:modules-extra,代码行数:14,代码来源:QueryManager.java


示例14: fromIndexes

import com.mongodb.client.model.Indexes; //导入依赖的package包/类
private Bson fromIndexes(List<Bson> indexes) {
	if(indexes.size() == 1) {
		return indexes.get(0);
	}
	return Indexes.compoundIndex(indexes);
}
 
开发者ID:JPDSousa,项目名称:mongo-obj-framework,代码行数:7,代码来源:InternalIndex.java


示例15: ascending

import com.mongodb.client.model.Indexes; //导入依赖的package包/类
public MongoIndex ascending(String... keys) {
    this.bson = Indexes.ascending(keys);
    return this;
}
 
开发者ID:T-baby,项目名称:MongoDB-Plugin,代码行数:5,代码来源:MongoIndex.java


示例16: descending

import com.mongodb.client.model.Indexes; //导入依赖的package包/类
public MongoIndex descending(String... keys) {
    this.bson = Indexes.descending(keys);
    return this;
}
 
开发者ID:T-baby,项目名称:MongoDB-Plugin,代码行数:5,代码来源:MongoIndex.java


示例17: geo2dsphere

import com.mongodb.client.model.Indexes; //导入依赖的package包/类
public MongoIndex geo2dsphere(String... keys) {
    this.bson = Indexes.geo2dsphere(keys);
    return this;
}
 
开发者ID:T-baby,项目名称:MongoDB-Plugin,代码行数:5,代码来源:MongoIndex.java


示例18: geo2d

import com.mongodb.client.model.Indexes; //导入依赖的package包/类
public MongoIndex geo2d(String key) {
    this.bson = Indexes.geo2d(key);
    return this;
}
 
开发者ID:T-baby,项目名称:MongoDB-Plugin,代码行数:5,代码来源:MongoIndex.java


示例19: geoHaystack

import com.mongodb.client.model.Indexes; //导入依赖的package包/类
public MongoIndex geoHaystack(String key, Bson additional) {
    this.bson = Indexes.geoHaystack(key, additional);
    return this;
}
 
开发者ID:T-baby,项目名称:MongoDB-Plugin,代码行数:5,代码来源:MongoIndex.java


示例20: text

import com.mongodb.client.model.Indexes; //导入依赖的package包/类
public MongoIndex text(String key) {
    this.bson = Indexes.text(key);
    return this;
}
 
开发者ID:T-baby,项目名称:MongoDB-Plugin,代码行数:5,代码来源:MongoIndex.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java IDrawableStatic类代码示例发布时间:2022-05-22
下一篇:
Java TObjectIntIterator类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap