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


Java FindIterable.iterator方法代码示例

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


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

示例1: findOne

import com.mongodb.client.FindIterable; //导入方法依赖的package包/类
/**
 * 查询一个
 *
 * @param collectionName 集合名
 * @param query          查询条件
 * @param fields         返回字段或者排除字段
 * @param sort
 * @return
 */
public Map<String, Object> findOne(
        String collectionName,
        MongodbQuery query, MongodbFields fields, MongodbSort sort) {
    MongoCollection<Document> collection = sMongoDatabase.getCollection(collectionName);
    FindIterable<Document> findIterable = collection.find(query.getQuery());
    if (fields == null) {
        findIterable.projection(new MongodbFields().getDbObject());
    } else {
        findIterable.projection(fields.getDbObject());
    }
    if (sort != null) {
        findIterable.sort(sort.getDbObject());
    }
    findIterable.limit(1);
    MongoCursor<Document> cursor = findIterable.iterator();
    try {
        if (cursor.hasNext()) {
            return cursor.next();
        }
    } finally {
        cursor.close();
    }
    return null;
}
 
开发者ID:wxz1211,项目名称:dooo,代码行数:34,代码来源:MongodbDataAccess.java

示例2: AddFlowerRatingReturnsTrueWithValidJsonInput

import com.mongodb.client.FindIterable; //导入方法依赖的package包/类
@Test
public void AddFlowerRatingReturnsTrueWithValidJsonInput() throws IOException{

    String json = "{like: true, id: \"58d1c36efb0cac4e15afd202\"}";

    assertTrue(plantController.addFlowerRating(json, "first uploadId") instanceof ObjectId);

    MongoClient mongoClient = new MongoClient();
    MongoDatabase db = mongoClient.getDatabase(databaseName);
    MongoCollection plants = db.getCollection("plants");

    FindIterable doc = plants.find(new Document().append("_id", new ObjectId("58d1c36efb0cac4e15afd202")));
    Iterator iterator = doc.iterator();
    Document result = (Document) iterator.next();

    List<Document> ratings = (List<Document>) ((Document) result.get("metadata")).get("ratings");
    assertEquals(1, ratings.size());

    Document rating = ratings.get(0);
    assertTrue(rating.getBoolean("like"));
    assertTrue(rating.get("id") instanceof ObjectId);
}
 
开发者ID:UMM-CSci-3601-S17,项目名称:digital-display-garden-iteration-4-dorfner-v2,代码行数:23,代码来源:FlowerRating.java

示例3: AddFlowerRatingReturnsTrueWithValidInput

import com.mongodb.client.FindIterable; //导入方法依赖的package包/类
@Test
public void AddFlowerRatingReturnsTrueWithValidInput() throws IOException{

    assertTrue(plantController.addFlowerRating("16001.0", true, "first uploadId"));
    MongoCollection plants = testDB.getCollection("plants");

    FindIterable doc = plants.find(new Document().append("_id", new ObjectId("58d1c36efb0cac4e15afd202")));
    Iterator iterator = doc.iterator();
    Document result = (Document) iterator.next();

    List<Document> ratings = (List<Document>) ((Document) result.get("metadata")).get("ratings");
    assertEquals(1, ratings.size());

    Document rating = ratings.get(0);
    //assertTrue(rating.getBoolean("like"));
    //assertEquals(new ObjectId("58d1c36efb0cac4e15afd202"),rating.get("ratingOnObjectOfId"));
}
 
开发者ID:UMM-CSci-3601-S17,项目名称:digital-display-garden-iteration-4-revolverenguardia-1,代码行数:18,代码来源:FlowerRating.java

示例4: failedInputOfComment

import com.mongodb.client.FindIterable; //导入方法依赖的package包/类
@Test
public void failedInputOfComment() throws IOException {
    String json = "{ plantId: \"58d1c36efb0cac4e15afd27\", comment : \"Here is our comment for this test\" }";

    assertFalse(plantController.addComment(json, "second uploadId"));

    MongoClient mongoClient = new MongoClient();
    MongoDatabase db = mongoClient.getDatabase(databaseName);
    MongoCollection<Document> plants = db.getCollection("plants");

    FindIterable findIterable = plants.find();
    Iterator iterator = findIterable.iterator();
    while(iterator.hasNext()){
        Document plant = (Document) iterator.next();
        List<Document> plantComments = (List<Document>) ((Document) plant.get("metadata")).get("comments");
        assertEquals(0,plantComments.size());
    }
}
 
开发者ID:UMM-CSci-3601-S17,项目名称:digital-display-garden-iteration-4-dorfner-v2,代码行数:19,代码来源:TestPlantComment.java

示例5: findAndConsumer

import com.mongodb.client.FindIterable; //导入方法依赖的package包/类
/**
 * 查询并逐条处理
 *
 * @param collectionName 集合名
 * @param query          查询条件
 * @param fields         返回字段或者排除字段
 * @param sort           排序方式
 * @param consumer       记录处理
 * @return
 */
public void findAndConsumer(
        String collectionName,
        MongodbQuery query, MongodbFields fields,
        MongodbSort sort, Consumer<Map<String, Object>> consumer) {
    MongoCollection<Document> collection = sMongoDatabase.getCollection(collectionName);
    FindIterable<Document> findIterable = collection.find(query == null ? new Document() : query.getQuery());
    if (fields == null) {
        findIterable.projection(new MongodbFields().getDbObject());
    } else {
        findIterable.projection(fields.getDbObject());
    }
    if (sort != null) {
        findIterable.sort(sort.getDbObject());
    }
    MongoCursor<Document> cursor = findIterable.iterator();
    try {
        while (cursor.hasNext()) {
            Map<String, Object> document = cursor.next();
            consumer.accept(document);
        }
    } finally {
        cursor.close();
    }
}
 
开发者ID:wxz1211,项目名称:dooo,代码行数:35,代码来源:MongodbDataAccess.java

示例6: findAll

import com.mongodb.client.FindIterable; //导入方法依赖的package包/类
/**
 * 查询
 *
 * @param clazz          类
 * @param collectionName 集合名
 * @param sort           排序
 * @param <T>
 * @return
 */
public <T> List<T> findAll(Class<T> clazz, String collectionName, MongodbSort sort) {
    List<T> resultMapList = new ArrayList<T>();
    MongoCollection<Document> collection = sMongoDatabase.getCollection(collectionName);
    FindIterable<Document> findIterable = collection.find();
    if(sort != null) {
        findIterable.sort(sort.getDbObject());
    }
    MongoCursor<Document> cursor = findIterable.iterator();
    try {
        while (cursor.hasNext()) {
            Document document = cursor.next();
            T parseObject = JSON.parseObject(JSON.toJSONString(document), clazz);
            resultMapList.add(parseObject);
        }
    } finally {
        cursor.close();
    }

    return resultMapList;
}
 
开发者ID:wxz1211,项目名称:dooo,代码行数:30,代码来源:MongodbDataAccess.java

示例7: AddFlowerRatingReturnsTrueWithValidJsonInput

import com.mongodb.client.FindIterable; //导入方法依赖的package包/类
@Test
public void AddFlowerRatingReturnsTrueWithValidJsonInput() throws IOException{

    String json = "{like: true, id: \"16001.0\"}";

    assertTrue(plantController.addFlowerRating(json, "first uploadId"));

    MongoCollection plants = testDB.getCollection("plants");

    FindIterable doc = plants.find(new Document().append("_id", new ObjectId("58d1c36efb0cac4e15afd202")));
    Iterator iterator = doc.iterator();
    Document result = (Document) iterator.next();

    List<Document> ratings = (List<Document>) ((Document) result.get("metadata")).get("ratings");
    assertEquals(1, ratings.size());

    Document rating = ratings.get(0);
    assertTrue(rating.getBoolean("like"));
    assertEquals(new ObjectId("58d1c36efb0cac4e15afd202"),rating.get("ratingOnObjectOfId"));
}
 
开发者ID:UMM-CSci-3601-S17,项目名称:digital-display-garden-iteration-4-revolverenguardia-1,代码行数:21,代码来源:FlowerRating.java

示例8: TestBedVisit

import com.mongodb.client.FindIterable; //导入方法依赖的package包/类
@Test
public void TestBedVisit(){
    bedController.addBedVisit("10.0","first uploadId");
    MongoCollection beds = testDB.getCollection("beds");

    FindIterable doc = beds.find(new Document().append("_id", new ObjectId("58d1c36efb0cac4e15afd303")));
    Iterator iterator = doc.iterator();
    Document result = (Document) iterator.next();
    //System.out.println(result);

    List<Document> bedVisits =  (List<Document>)((Document) result.get("metadata")).get("bedVisits");
    //System.out.println(bedVisits);
    assertEquals("",1 ,bedVisits.size());

    Document visits = bedVisits.get(0);
    //System.out.println(visits.get("visit"));
    ObjectId objectId = new ObjectId();

    String v = visits.get("visit").toString();

    //checking to see that the type of visit is an of type/structure of ObjectID
    assertEquals("they should both be of type org.bson.types.ObjectId ",objectId.getClass().getName(),visits.get("visit").getClass().getName());
    assertEquals("the object id produced from a visit must be 24 characters",24,v.length());

}
 
开发者ID:UMM-CSci-3601-S17,项目名称:digital-display-garden-iteration-4-revolverenguardia-1,代码行数:26,代码来源:TestBedController.java

示例9: AddFlowerRatingReturnsTrueWithValidInput

import com.mongodb.client.FindIterable; //导入方法依赖的package包/类
@Test
public void AddFlowerRatingReturnsTrueWithValidInput() throws IOException{

    assertTrue(plantController.addFlowerRating("58d1c36efb0cac4e15afd202", true, "first uploadId"));

    MongoClient mongoClient = new MongoClient();
    MongoDatabase db = mongoClient.getDatabase(databaseName);
    MongoCollection plants = db.getCollection("plants");

    FindIterable doc = plants.find(new Document().append("_id", new ObjectId("58d1c36efb0cac4e15afd202")));
    Iterator iterator = doc.iterator();
    Document result = (Document) iterator.next();

    List<Document> ratings = (List<Document>) ((Document) result.get("metadata")).get("ratings");
    assertEquals(1, ratings.size());

    Document rating = ratings.get(0);
    assertTrue(rating.getBoolean("like"));
    assertEquals(new ObjectId("58d1c36efb0cac4e15afd202"),rating.get("ratingOnObjectOfId"));
}
 
开发者ID:UMM-CSci-3601-S17,项目名称:digital-display-garden-iteration-3-sixguysburgers-fries,代码行数:21,代码来源:FlowerRating.java

示例10: AddFlowerRatingReturnsTrueWithValidJsonInput

import com.mongodb.client.FindIterable; //导入方法依赖的package包/类
@Test
public void AddFlowerRatingReturnsTrueWithValidJsonInput() throws IOException{

    String json = "{like: true, id: \"58d1c36efb0cac4e15afd202\"}";

    assertTrue(plantController.addFlowerRating(json, "first uploadId"));

    MongoClient mongoClient = new MongoClient();
    MongoDatabase db = mongoClient.getDatabase(databaseName);
    MongoCollection plants = db.getCollection("plants");

    FindIterable doc = plants.find(new Document().append("_id", new ObjectId("58d1c36efb0cac4e15afd202")));
    Iterator iterator = doc.iterator();
    Document result = (Document) iterator.next();

    List<Document> ratings = (List<Document>) ((Document) result.get("metadata")).get("ratings");
    assertEquals(1, ratings.size());

    Document rating = ratings.get(0);
    assertTrue(rating.getBoolean("like"));
    assertEquals(new ObjectId("58d1c36efb0cac4e15afd202"),rating.get("ratingOnObjectOfId"));
}
 
开发者ID:UMM-CSci-3601-S17,项目名称:digital-display-garden-iteration-3-sixguysburgers-fries,代码行数:23,代码来源:FlowerRating.java

示例11: AddFlowerRatingReturnsTrueWithValidInput

import com.mongodb.client.FindIterable; //导入方法依赖的package包/类
@Test
public void AddFlowerRatingReturnsTrueWithValidInput() throws IOException{
    assertTrue(plantController.addFlowerRating("58d1c36efb0cac4e15afd202", true, "first uploadId") instanceof ObjectId);

    MongoClient mongoClient = new MongoClient();
    MongoDatabase db = mongoClient.getDatabase(databaseName);
    MongoCollection plants = db.getCollection("plants");

    FindIterable doc = plants.find(new Document().append("_id", new ObjectId("58d1c36efb0cac4e15afd202")));
    Iterator iterator = doc.iterator();
    Document result = (Document) iterator.next();

    List<Document> ratings = (List<Document>) ((Document) result.get("metadata")).get("ratings");
    assertEquals(1, ratings.size());

    Document rating = ratings.get(0);
    assertTrue(rating.getBoolean("like"));
    assertTrue(rating.get("id") instanceof ObjectId);
}
 
开发者ID:UMM-CSci-3601-S17,项目名称:digital-display-garden-iteration-4-dorfner-v2,代码行数:20,代码来源:FlowerRating.java

示例12: find

import com.mongodb.client.FindIterable; //导入方法依赖的package包/类
/**
 * 查找指定条数的数据
 */
public List<Map<String, Object>> find(String collectionName, Integer pageNumber, Integer pageSize) {
    MongoCollection collection = mongoDatabase.getCollection(collectionName);
    List<Map<String, Object>> list = new ArrayList<>();
    if (collection == null) {
        return list;
    }
    FindIterable findIterable = collection.find();

    if (pageSize != null && pageSize >= 0) {
        if (pageNumber != null && pageNumber >= 1) {
            findIterable = findIterable.skip((pageNumber - 1) * pageSize);
        }
        findIterable = findIterable.limit(pageSize);
    }
    Iterator<Document> iterator = findIterable.iterator();
    while (iterator.hasNext()) {
        Document document = iterator.next();
        document.remove("_id");
        Map<String, Object> map = new HashMap<>(document);
        list.add(map);
    }
    return list;
}
 
开发者ID:wxz1211,项目名称:dooo,代码行数:27,代码来源:SimpleMongodbAccessor.java

示例13: find

import com.mongodb.client.FindIterable; //导入方法依赖的package包/类
private Object find(String filter) throws ServiceException {
	try {
		List<Map<String, Object>> result = new ArrayList<Map<String, Object>>();

		FindIterable<Document> cursor = null;
		if (filter != null) {
			BasicDBObject filterObj = BasicDBObject.parse(filter);
			cursor = this.collection.find(filterObj);
		} else {
			cursor = this.collection.find();
		}

		if (cursor != null) {
			MongoCursor<Document> iterator = cursor.iterator();
			while (iterator.hasNext()) {
				result.add(iterator.next());
			}
		}
		return result;
	} catch (Exception e) {
		throw new ServiceException("Search Exception: " + e.getMessage());
	}
}
 
开发者ID:PinaeOS,项目名称:pumbaa,代码行数:24,代码来源:MongodbService.java

示例14: queryDataTest

import com.mongodb.client.FindIterable; //导入方法依赖的package包/类
@Test
public void queryDataTest() {
	BasicDBObject fields = new BasicDBObject();
	fields.put("likes", new BasicDBObject("$gt", 16));
	FindIterable<Document> iterable = mongoPool.getDB()
			.getCollection("test").find(fields);
	MongoCursor<Document> cursor = iterable.iterator();
	System.out.println(cursor);
	while (cursor.hasNext()) {
		Document document = cursor.next();
		
		System.out.println(document);
		
		if (document.get("append") != null) {
			System.out.println(document.get("append") instanceof Document);
		}
	}
}
 
开发者ID:lolog,项目名称:mogodb-dao,代码行数:19,代码来源:MongoAndSpringTest.java

示例15: fillFromCursor

import com.mongodb.client.FindIterable; //导入方法依赖的package包/类
private void fillFromCursor(List<AuditLogEntry> ret, FindIterable<Document> cursor) throws MongoException {
    Iterator<Document> iterator = cursor.iterator();
    while (iterator.hasNext()) {
        Document obj = iterator.next();
        AuditLogEntry entry = new AuditLogEntry();
        entry.setLevel((Integer) obj.get(LEVEL));
        entry.setMessage(safeString(obj, MESSAGE));
        entry.setUser(safeString(obj, USER));
        entry.setLogId(safeString(obj, LOG_ID));
        entry.setWhen((Date) obj.get(WHEN));
        entry.setSource(safeString(obj, SOURCE));
        entry.setEntryId(safeString(obj, ENTRY_ID));
        entry.setCategory(safeString(obj, CATEGORY));
        ret.add(entry);
    }
}
 
开发者ID:RapturePlatform,项目名称:Rapture,代码行数:17,代码来源:MongoDBAuditLog.java


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