本文整理匯總了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;
}
示例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();
}
}
示例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;
}
示例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;
}
示例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());
}
}
示例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);
}
}
}
示例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);
}
}