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

Java ListIndexesIterable类代码示例

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

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



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

示例1: getCollectionIndexes

import com.mongodb.client.ListIndexesIterable; //导入依赖的package包/类
/**
 *
 * @param dbName
 * @param collName
 * @return
 */
List<BsonDocument> getCollectionIndexes(String dbName, String collName) {
    List<BsonDocument> ret = new ArrayList<>();

    ListIndexesIterable<Document> indexes = client
            .getDatabase(dbName)
            .getCollection(collName, BsonDocument.class)
            .listIndexes();

    indexes.iterator().forEachRemaining(
            i -> {
                BsonDocument bi = BsonDocument.parse(i.toJson());

                BsonValue name = bi.remove("name");
                bi.put("_id", name);

                ret.add(bi);
            });

    return ret;
}
 
开发者ID:SoftInstigate,项目名称:restheart,代码行数:27,代码来源:IndexDAO.java


示例2: getIndexNames

import com.mongodb.client.ListIndexesIterable; //导入依赖的package包/类
public static Set<String> getIndexNames(MongoCollection<Document> collection) {
    ListIndexesIterable<Document> currentIndexes = collection.listIndexes();
    MongoCursor<Document> cursor = currentIndexes.iterator();
    Set<String> indexNames = new HashSet<>();
    while (cursor.hasNext()) {
        Object next = cursor.next();
        String name = ((Document) next).get("name").toString();
        indexNames.add(name);
    }
    return indexNames;
}
 
开发者ID:Asymmetrik,项目名称:nifi-nars,代码行数:12,代码来源:AbstractMongoProcessor.java


示例3: emptySecondaryIndexTest

import com.mongodb.client.ListIndexesIterable; //导入依赖的package包/类
@Test
public void emptySecondaryIndexTest() throws Exception {
    final TestRunner runner = TestRunners.newTestRunner(new StoreInMongo());

    addMongoService(runner);
    runner.setProperty(MongoProps.DATABASE, MONGO_DATABASE_NAME);
    runner.setProperty(MongoProps.COLLECTION, "index_test");
    // runner.setProperty(MongoProps.INDEX, "[{\"a\": 1}]");

    runner.run();

    // Connect to mongo to inspect indexes
    MongoClient client = mongo.getMongoClient();
    ListIndexesIterable<Document> indexes = client.getDatabase(MONGO_DATABASE_NAME).getCollection("index_test").listIndexes();

    List<Document> indexesArray = new ArrayList<>();
    indexesArray = indexes.into(indexesArray);

    // Check for compound index
    boolean hasCompound = false;
    for (Document doc : indexesArray) {
        if (doc.get("name").toString().equals("t_1_s_1")) {
            hasCompound = true;
        }
    }
    assertFalse("Should not have compound index", hasCompound);
}
 
开发者ID:Asymmetrik,项目名称:nifi-nars,代码行数:28,代码来源:StoreInMongoIT.java


示例4: loadDBIndexes

import com.mongodb.client.ListIndexesIterable; //导入依赖的package包/类
private Set<InternalIndex> loadDBIndexes() {
	final ListIndexesIterable<BsonDocument> bsonIndexes = collection.listIndexes(BsonDocument.class);
	final Set<InternalIndex> indexes = Sets.newLinkedHashSet();
	for(BsonDocument bsonIndex : bsonIndexes) {
		indexes.add(InternalIndex.fromBson(bsonIndex));
	}
	return indexes;
}
 
开发者ID:JPDSousa,项目名称:mongo-obj-framework,代码行数:9,代码来源:SmofCollectionImpl.java


示例5: createIndex

import com.mongodb.client.ListIndexesIterable; //导入依赖的package包/类
private void createIndex(IndexDefinition indexDefinition, boolean force) {
    // create index if not exists... use index name too from indexDefinition
    // object
    if (indexDefinition == null) {
        return;
    }

    String indexName = IndexNameFactory.createIndexName(indexDefinition);
    MongoCollection<Document> collection = MongoDBFactory.getCollection(instanceName, tableName);

    int limit = Integer.parseInt(
            MultiValueConfigLoader.getConfig("MONGODB-" + instanceName + ".limit", MultiValueConfigLoader.getConfig("MONGODB-default.limit", "250")));

    boolean indexExists = false;
    ListIndexesIterable<Document> indexInfo = collection.listIndexes();
    for (Document dbObject : indexInfo) {
        Object name = dbObject.get("name");
        if (name != null && name.toString().equals(indexName)) {
            indexExists = true;
            break;
        }
    }
    if (force || collection.count() < limit) {
        createIt(indexDefinition, force, indexName, collection);
    } else {
        if (!indexExists) {
            log.warn(tableName + " collection has more than " + limit + " items. please index manually");
        }
    }
}
 
开发者ID:RapturePlatform,项目名称:Rapture,代码行数:31,代码来源:MongoIndexHandler.java


示例6: queryIndex

import com.mongodb.client.ListIndexesIterable; //导入依赖的package包/类
@Override
public Map<String, Object> queryIndex () {
	// get current collection name
	String collectionNameForT = getCollectionName(collectionNames.get());
	
	// Indexes Iterator
	ListIndexesIterable iterable = database.getCollection(collectionNameForT).listIndexes();
	
	// cycle the indexes
	Iterator iterator = iterable.iterator();
	
	List<String> indexes    = new ArrayList<String>();
	List<Keys>   keys       = new ArrayList<Keys>();
	Map<String, Object> map = new HashMap<String, Object>();
	
	while (iterator.hasNext()) {
		// read value
		Document document = (Document) iterator.next();
		Keys indexKey = new Keys();
		
		// cycle key
		for (String key :document.get("key", Document.class).keySet()) {
			indexes.add(key);
			indexKey.setKey(key);
			// key's order value
			indexKey.setOrder(document.get("key", Document.class).getInteger(key));
		}
		
		indexKey.setName(document.getString("name"));
		indexKey.setNs(document.getString("ns"));
		indexKey.setBackground(document.getBoolean("background"));
		indexKey.setSparse(document.getBoolean("sparse"));
		
		keys.add(indexKey);
	}
	map.put("indexes", indexes);
	map.put("keys", keys);
	
	// gc
	gc();
	
	return map;
}
 
开发者ID:lolog,项目名称:mogodb-dao,代码行数:44,代码来源:MongoDaoImpl.java


示例7: listIndexes

import com.mongodb.client.ListIndexesIterable; //导入依赖的package包/类
@Override
public ListIndexesIterable<Document> listIndexes()
{
    return collection.listIndexes();
}
 
开发者ID:dd00f,项目名称:ibm-performance-monitor,代码行数:6,代码来源:ProfiledMongoCollection.java


示例8: testInsertDynamicityEnabledDBAndCollectionAndIndex

import com.mongodb.client.ListIndexesIterable; //导入依赖的package包/类
@Test
public void testInsertDynamicityEnabledDBAndCollectionAndIndex() {
    assertEquals(0, testCollection.count());
    mongo.getDatabase("otherDB").drop();
    db.getCollection("otherCollection").drop();
    assertFalse("The otherDB database should not exist",
            StreamSupport.stream(mongo.listDatabaseNames().spliterator(), false)
                    .anyMatch("otherDB"::equals));

    String body = "{\"_id\": \"testInsertDynamicityEnabledDBAndCollection\", \"a\" : 1, \"b\" : 2}";
    Map<String, Object> headers = new HashMap<String, Object>();
    headers.put(MongoDbConstants.DATABASE, "otherDB");
    headers.put(MongoDbConstants.COLLECTION, "otherCollection");

    List<DBObject> objIndex = new ArrayList<DBObject>();
    DBObject index1 = new BasicDBObject();
    index1.put("a", 1);
    DBObject index2 = new BasicDBObject();
    index2.put("b", -1);
    objIndex.add(index1);
    objIndex.add(index2);

    headers.put(MongoDbConstants.COLLECTION_INDEX, objIndex);

    Object result = template.requestBodyAndHeaders("direct:dynamicityEnabled", body, headers);

    assertEquals("Response isn't of type WriteResult", BasicDBObject.class, result.getClass());

    MongoCollection<BasicDBObject> dynamicCollection = mongo.getDatabase("otherDB").getCollection("otherCollection", BasicDBObject.class);

    ListIndexesIterable<DBObject> indexInfos = dynamicCollection.listIndexes(DBObject.class);

    MongoCursor<DBObject> iterator = indexInfos.iterator();
    iterator.next();
    BasicDBObject key1 = (BasicDBObject) iterator.next().get("key");
    BasicDBObject key2 = (BasicDBObject) iterator.next().get("key");

    assertTrue("No index on the field a", key1.containsField("a") && "1".equals(key1.getString("a")));
    assertTrue("No index on the field b", key2.containsField("b") && "-1".equals(key2.getString("b")));

    DBObject b = dynamicCollection.find(new BasicDBObject("_id", "testInsertDynamicityEnabledDBAndCollection")).first();
    assertNotNull("No record with 'testInsertDynamicityEnabledDBAndCollection' _id", b);

    b = testCollection.find(new BasicDBObject("_id", "testInsertDynamicityEnabledDBOnly")).first();
    assertNull("There is a record with 'testInsertDynamicityEnabledDBAndCollection' _id in the test collection", b);

    assertTrue("The otherDB database should exist",
            StreamSupport.stream(mongo.listDatabaseNames().spliterator(), false)
                    .anyMatch("otherDB"::equals));
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:51,代码来源:MongoDbIndexTest.java


示例9: testUpdate

import com.mongodb.client.ListIndexesIterable; //导入依赖的package包/类
@Test
public void testUpdate() {
	TestObject o = new TestObject();
	o.setName("bar");
	o.setValue(new BigDecimal("5"));
	Assert.assertEquals("bar", o.getName());
	String id = o.getId();
	
	TestObject save = Tester.dao.save(o);
	Assert.assertEquals("bar", save.getName());
	ABaseTest.assertEquals(new BigDecimal("5"), save.getValue());
	Assert.assertNotNull(save.getId());
	Assert.assertNotNull(save.getDt());
	
	TestObject find = Tester.dao.findById(id);
	Assert.assertNotNull(find);
	Assert.assertEquals("bar", find.getName());
	ABaseTest.assertEquals(new BigDecimal("5"), find.getValue());
	Assert.assertEquals(id, find.getId());
	Assert.assertNotNull(find.getDt());
	
	find.setName("blubb");
	
	TestObject save2 = Tester.dao.save(find);
	Assert.assertNotNull(save2);
	Assert.assertEquals("blubb", save2.getName());
	ABaseTest.assertEquals(new BigDecimal("5"), save2.getValue());
	Assert.assertEquals(id, save2.getId());
	Assert.assertNotNull(save2.getDt());
	
	TestObject find3 = Tester.dao.findByName("blubb");
	Assert.assertNotNull(find3);
	Assert.assertEquals("blubb", find3.getName());
	ABaseTest.assertEquals(new BigDecimal("5"), find3.getValue());
	Assert.assertEquals(id, find3.getId());
	Assert.assertNotNull(find3.getDt());
	
	Tester.dao.delete(id);
	
	TestObject find2 = Tester.dao.findById(id);
	Assert.assertNull(find2);
	
	ListIndexesIterable<Document> listIndexes = ABaseTest.mongo.getDatabase(ABaseTest.dbName).getCollection("TestObject").listIndexes();
	MongoCursor<Document> iterator = listIndexes.iterator();
	while (iterator.hasNext()) {
		Object index = iterator.next();
		System.out.println(index.toString());
	}
}
 
开发者ID:taimos,项目名称:spring-dao-mongo,代码行数:50,代码来源:Tester.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Java EncryptionConstants类代码示例发布时间:2022-05-22
下一篇:
Java Buffer类代码示例发布时间: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