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


Java FindIterable.limit方法代码示例

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


在下文中一共展示了FindIterable.limit方法的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: find

import com.mongodb.client.FindIterable; //导入方法依赖的package包/类
/**
 * 查找指定条数的数据
 */
public <T> List<T> find(String collectionName, Integer pageNumber, Integer pageSize, Class<T> clazz) {
    MongoCollection collection = mongoDatabase.getCollection(collectionName);
    List<T> 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");
        T t = JSON.parseObject(document.toJson(), clazz);
        list.add(t);
    }
    return list;
}
 
开发者ID:wxz1211,项目名称:dooo,代码行数:27,代码来源:SimpleMongodbAccessor.java

示例3: query

import com.mongodb.client.FindIterable; //导入方法依赖的package包/类
private FindIterable<Document> query(final Bson filter, final Bson sort, final Bson projection, final int offset, final int count) {
    if (offset < 0 || count < 0) {
        throw new IllegalArgumentException("offset (" + offset + ") and count(" + count + ") can't be negative");
    }

    FindIterable<Document> findIterable = coll.find(filter);

    if (projection != null) {
        findIterable = findIterable.projection(projection);
    }

    if (sort != null) {
        findIterable = findIterable.sort(sort);
    }

    if (offset > 0) {
        findIterable = findIterable.skip(offset);
    }

    if (count < Integer.MAX_VALUE) {
        findIterable = findIterable.limit(count);
    }

    return findIterable;
}
 
开发者ID:landawn,项目名称:AbacusUtil,代码行数:26,代码来源:MongoCollectionExecutor.java

示例4: applyPropertiesToCursor

import com.mongodb.client.FindIterable; //导入方法依赖的package包/类
private void applyPropertiesToCursor( MongoIterable<Document> mongoIterable, QueryProperties queryProps, 
         boolean includeMetaDataSearchLimit, boolean includeSortExpr )
 {
     if( includeMetaDataSearchLimit )
     {
         Integer searchLimit = getModel().getEffectiveMDSearchLimit( queryProps ); 
         if( searchLimit > 0 )
{
             // Apply to FindIterable or MapReduceIterable
	if ( mongoIterable instanceof FindIterable )
	{
		FindIterable<Document> findIterable = (FindIterable<Document>) mongoIterable;
		findIterable.limit( searchLimit.intValue( ) );
	}
	else if ( mongoIterable instanceof MapReduceIterable )
	{
		MapReduceIterable<Document> mapReduceIterable = (MapReduceIterable<Document>) mongoIterable;
		mapReduceIterable.limit( searchLimit.intValue( ) );
	}       
}
     }
     
     applyPropertiesToCursor( mongoIterable, queryProps, includeSortExpr );
 }
 
开发者ID:eclipse,项目名称:birt,代码行数:25,代码来源:MDbOperation.java

示例5: getDocumentMongoCursor

import com.mongodb.client.FindIterable; //导入方法依赖的package包/类
private MongoCursor<Document> getDocumentMongoCursor(Table table, List<FilterItem> whereItems, int firstRow,
        int maxRows, Consumer<FilterItem> filterItemsToPostProcessConsumer) {
    final MongoCollection<Document> collection = _mongoDb.getCollection(table.getName());

    final Document query = createMongoDbQuery(table, whereItems, filterItemsToPostProcessConsumer);

    logger.info("Executing MongoDB 'find' query: {}", query);
    FindIterable<Document> iterable = collection.find(query);

    if (maxRows > 0) {
        iterable = iterable.limit(maxRows);
    }
    if (firstRow > 1) {
        final int skip = firstRow - 1;
        iterable = iterable.skip(skip);
    }

    return iterable.iterator();
}
 
开发者ID:apache,项目名称:metamodel,代码行数:20,代码来源:MongoDbDataContext.java

示例6: find

import com.mongodb.client.FindIterable; //导入方法依赖的package包/类
/**
 * 查询
 *
 * @param collectionName 集合名
 * @param query          查询条件
 * @param fields         返回字段或者排除字段
 * @param sort           排序方式
 * @param pageInfo       分页
 * @return
 */
public List<Map<String, Object>> find(
        String collectionName,
        MongodbQuery query, MongodbFields fields,
        MongodbSort sort, MongodbPageInfo pageInfo) {
    List<Map<String, Object>> resultMapList = new ArrayList<Map<String, Object>>();
    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());
    }
    if (pageInfo != null) {
        int startPos = pageInfo.getPageIndex() * pageInfo.getPageSize();
        int rows = pageInfo.getPageSize();
        if (startPos > 0) {
            findIterable.skip(startPos - 1);
        }
        findIterable.limit(rows);
    }
    MongoCursor<Document> cursor = findIterable.iterator();
    try {
        while (cursor.hasNext()) {
            Map<String, Object> document = cursor.next();
            resultMapList.add(document);
        }
    } finally {
        cursor.close();
    }

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

示例7: fetchDataFromBackEnd

import com.mongodb.client.FindIterable; //导入方法依赖的package包/类
protected List<T> fetchDataFromBackEnd(Query<T, Bson> query) {
    Bson filter = getFilter(query);
    FindIterable<T> findIterable = mongoCollection.find();
    if (filter != null) findIterable = findIterable.filter(filter);
    findIterable = findIterable.skip(query.getOffset());
    findIterable = findIterable.limit(query.getLimit());
    findIterable = findIterable.sort(getSorts(query.getSortOrders()));

    final List<T> data = new ArrayList<T>();
    findIterable.iterator().forEachRemaining(data::add);
    return data;
}
 
开发者ID:andyphillips404,项目名称:awplab-core,代码行数:13,代码来源:MongoDataProvider.java

示例8: getDocuments

import com.mongodb.client.FindIterable; //导入方法依赖的package包/类
public List<Document> getDocuments(List<KeyValue> cond, RESOURCE_TYPE resType, String sortKey, boolean asc, int limit) {

		ArrayList<Document> docList = new ArrayList<Document>();
		
		Iterator<KeyValue> it = cond.iterator();
		KeyValue kv = it.next();
		BasicDBObject query = new BasicDBObject(kv.getKey(), kv.getValue());
		while (it.hasNext()) {
			kv = it.next();
			query.append(kv.getKey(), kv.getValue());
		}
	
		BasicDBObject sort = null;
		if (sortKey != null) {
			sort = new BasicDBObject(sortKey, asc ? 1 : -1);
		}

		MongoCollection<Document> collection = context.getDatabaseManager()
				.getCollection(collectionName);
		MongoCursor<Document> cursor;
		FindIterable<Document> find = collection.find(query);
		if (sort != null) {
			find = find.sort(sort);			
		}
		if (limit >= 0) {
			find = find.limit(limit);
		}
		cursor = find.iterator();
				
		while (cursor.hasNext()) {
			docList.add(cursor.next());
		}

		return docList;

	}
 
开发者ID:iotoasis,项目名称:SI,代码行数:37,代码来源:ResourceDAO.java

示例9: iterator

import com.mongodb.client.FindIterable; //导入方法依赖的package包/类
@Override
public Iterator<Document> iterator() {
    FindIterable fi = dc.getCollection().find(query.getQuery()).sort(query.getSort());
    if (limit != -1) {
        fi = fi.limit(limit);
    }
    if (skip != -1) {
        fi = fi.skip(skip);
    }

    cursor = fi.iterator();
    return new Iterator<Document>() {
        @Override
        public boolean hasNext() {
            return cursor.hasNext();
        }

        @Override
        public Document next() {
            org.bson.Document dbObject = (org.bson.Document) cursor.next();
            return dc.getDocumentForBSON(dbObject);
        }

        @Override
        public void remove() {
            cursor.remove();
        }
    };
}
 
开发者ID:KAOREND,项目名称:reactive-hamster,代码行数:30,代码来源:DocumentCursor.java

示例10: read

import com.mongodb.client.FindIterable; //导入方法依赖的package包/类
@ExtDirectMethod(STORE_READ)
public ExtDirectStoreResult<User> read(ExtDirectStoreReadRequest request) {

	List<Bson> andFilters = new ArrayList<>();
	StringFilter filter = request.getFirstFilterForField("filter");
	if (filter != null) {
		List<Bson> orFilters = new ArrayList<>();
		orFilters.add(Filters.regex(CUser.loginName, filter.getValue(), "i"));
		orFilters.add(Filters.regex(CUser.lastName, filter.getValue(), "i"));
		orFilters.add(Filters.regex(CUser.firstName, filter.getValue(), "i"));
		orFilters.add(Filters.regex(CUser.email, filter.getValue(), "i"));

		andFilters.add(Filters.or(orFilters));
	}
	andFilters.add(Filters.eq(CUser.deleted, false));

	long total = this.mongoDb.getCollection(User.class)
			.count(Filters.and(andFilters));

	FindIterable<User> find = this.mongoDb.getCollection(User.class)
			.find(Filters.and(andFilters));
	find.sort(Sorts.orderBy(QueryUtil.getSorts(request)));
	find.skip(request.getStart());
	find.limit(request.getLimit());

	return new ExtDirectStoreResult<>(total, QueryUtil.toList(find));
}
 
开发者ID:ralscha,项目名称:eds-starter6-mongodb,代码行数:28,代码来源:UserService.java

示例11: getCachedChronoVertices

import com.mongodb.client.FindIterable; //导入方法依赖的package包/类
public ArrayList<CachedChronoVertex> getCachedChronoVertices(BsonArray filters, String sortKey, Boolean isDesc,
		Integer limit) {
	ArrayList<CachedChronoVertex> vList = new ArrayList<CachedChronoVertex>();
	// Merge All the queries with $and
	CachedChronoGraph g = new CachedChronoGraph();
	BsonDocument baseQuery = new BsonDocument();
	FindIterable<BsonDocument> cursor;
	if (filters.isEmpty() == false) {
		baseQuery.put("$and", filters);
		cursor = vertices.find(baseQuery);
	} else {
		cursor = vertices.find();
	}
	if (sortKey != null) {
		if (isDesc == null)
			cursor.sort(new BsonDocument(sortKey, new BsonInt32(-1)));
		else if (isDesc == true) {
			cursor.sort(new BsonDocument(sortKey, new BsonInt32(-1)));
		} else
			cursor.sort(new BsonDocument(sortKey, new BsonInt32(1)));
	}
	if (limit != null)
		cursor.limit(limit);

	MongoCursor<BsonDocument> iter = cursor.iterator();
	while (iter.hasNext()) {
		BsonDocument doc = iter.next();
		String vid = doc.remove("_id").asString().getValue();
		CachedChronoVertex v = g.getChronoVertex(vid);
		v.setProperties(doc);
		vList.add(v);
	}
	return vList;
}
 
开发者ID:JaewookByun,项目名称:epcis,代码行数:35,代码来源:ChronoGraph.java

示例12: fetch

import com.mongodb.client.FindIterable; //导入方法依赖的package包/类
public FindIterable<Document> fetch(DbFilter query, int limit) {
    FindIterable<Document> iterable = getConnection().findSync(getCollection(), query == null ? null : query.toBson());
    if(limit != -1) iterable.limit(limit);
    return iterable;
}
 
开发者ID:Superioz,项目名称:MooProject,代码行数:6,代码来源:DatabaseCollection.java

示例13: onTrigger

import com.mongodb.client.FindIterable; //导入方法依赖的package包/类
@Override
public void onTrigger(ProcessContext context, ProcessSession session) throws ProcessException {
    FlowFile flowFile = session.get();
    if (flowFile == null) {
        return;
    }

    ComponentLog logger = this.getLogger();

    // Evaluate expression language and create BSON Documents
    Document query = (queryProperty.isSet()) ? Document.parse(queryProperty.evaluateAttributeExpressions(flowFile).getValue()) : null;
    Document projection = (projectionProperty.isSet()) ? Document.parse(projectionProperty.evaluateAttributeExpressions(flowFile).getValue()) : null;
    Document sort = (sortProperty.isSet()) ? Document.parse(sortProperty.evaluateAttributeExpressions(flowFile).getValue()) : null;

    try {
        FindIterable<Document> it = (query != null) ? collection.find(query) : collection.find();

        // Apply projection if needed
        if (projection != null) {
            it.projection(projection);
        }

        // Apply sort if needed
        if (sort != null) {
            it.sort(sort);
        }

        // Apply limit if set
        if (limit != null) {
            it.limit(limit.intValue());
        }

        // Iterate and create flowfile for each result
        final MongoCursor<Document> cursor = it.iterator();
        try {
            while (cursor.hasNext()) {
                // Create new flowfile with all parent attributes
                FlowFile ff = session.clone(flowFile);
                ff = session.write(ff, new OutputStreamCallback() {
                    @Override
                    public void process(OutputStream outputStream) throws IOException {
                        IOUtils.write(cursor.next().toJson(), outputStream);
                    }
                });

                session.transfer(ff, REL_SUCCESS);
            }
        } finally {
            cursor.close();
            session.remove(flowFile);
        }

    } catch (Exception e) {
        logger.error("Failed to execute query {} due to {}.", new Object[]{query, e}, e);
        flowFile = session.putAttribute(flowFile, "mongo.exception", e.getMessage());
        session.transfer(flowFile, REL_FAILURE);
    }
}
 
开发者ID:Asymmetrik,项目名称:nifi-nars,代码行数:59,代码来源:QueryMongo.java

示例14: runNativeQuery

import com.mongodb.client.FindIterable; //导入方法依赖的package包/类
@Override
public RaptureQueryResult runNativeQuery(final String repoType, final List<String> queryParams) {
    if (repoType.toUpperCase().equals(MONGODB)) {

        MongoRetryWrapper<RaptureQueryResult> wrapper = new MongoRetryWrapper<RaptureQueryResult>() {

            @Override
            public FindIterable<Document> makeCursor() {
                // Here we go, the queryParams are basically
                // (1) the searchCriteria
                Document queryObj = getQueryObjFromQueryParams(queryParams);
                // Document fieldObj =
                // getFieldObjFromQueryParams(queryParams);
                MongoCollection<Document> collection = MongoDBFactory.getCollection(instanceName, tableName);
                FindIterable<Document> find = collection.find(queryObj).batchSize(100);
                if (queryParams.size() > 2) {
                    Map<String, Object> options = JacksonUtil.getMapFromJson(queryParams.get(2));
                    if (options.containsKey(SKIP)) {
                        find.skip((Integer) options.get(SKIP));
                    }
                    if (options.containsKey(LIMIT)) {
                        find.limit((Integer) options.get(LIMIT));
                    }
                    if (options.containsKey(SORT)) {
                        Map<String, Object> sortInfo = JacksonUtil.getMapFromJson(options.get(SORT).toString());
                        Document sortInfoObject = new Document();
                        sortInfoObject.putAll(sortInfo);
                        find.sort(sortInfoObject);
                    }
                }
                return find;
            }

            @Override
            public RaptureQueryResult action(FindIterable<Document> iterable) {
                RaptureQueryResult res = new RaptureQueryResult();
                for (Document d : iterable) {
                    res.addRowContent(new JsonContent(d.toString()));
                }
                return res;
            }

        };
        return wrapper.doAction();
    } else {
        throw RaptureExceptionFactory.create(HttpURLConnection.HTTP_BAD_REQUEST, mongoMsgCatalog.getMessage("Mismatch", repoType));
    }
}
 
开发者ID:RapturePlatform,项目名称:Rapture,代码行数:49,代码来源:MongoDbDataStore.java

示例15: createDoFindAll

import com.mongodb.client.FindIterable; //导入方法依赖的package包/类
private Function<Exchange, Object> createDoFindAll() {
    return exchange1 -> {
        Iterable<BasicDBObject> result;
        MongoCollection<BasicDBObject> dbCol = calculateCollection(exchange1);
        // do not use getMandatoryBody, because if the body is empty we want to retrieve all objects in the collection
        BasicDBObject query = null;
        // do not run around looking for a type converter unless there is a need for it
        if (exchange1.getIn().getBody() != null) {
            query = exchange1.getIn().getBody(BasicDBObject.class);
        }
        BasicDBObject fieldFilter = exchange1.getIn().getHeader(MongoDbConstants.FIELDS_FILTER, BasicDBObject.class);

        // get the batch size and number to skip
        Integer batchSize = exchange1.getIn().getHeader(MongoDbConstants.BATCH_SIZE, Integer.class);
        Integer numToSkip = exchange1.getIn().getHeader(MongoDbConstants.NUM_TO_SKIP, Integer.class);
        Integer limit = exchange1.getIn().getHeader(MongoDbConstants.LIMIT, Integer.class);
        BasicDBObject sortBy = exchange1.getIn().getHeader(MongoDbConstants.SORT_BY, BasicDBObject.class);
        FindIterable<BasicDBObject> ret;
        if (query == null && fieldFilter == null) {
            ret = dbCol.find(new BasicDBObject());
        } else if (fieldFilter == null) {
            ret = dbCol.find(query);
        } else {
            ret = dbCol.find(new BasicDBObject()).projection(fieldFilter);
        }

        if (sortBy != null) {
            ret.sort(sortBy);
        }

        if (batchSize != null) {
            ret.batchSize(batchSize);
        }

        if (numToSkip != null) {
            ret.skip(numToSkip);
        }

        if (limit != null) {
            ret.limit(limit);
        }

        if (!MongoDbOutputType.DBCursor.equals(endpoint.getOutputType())) {
            try {
                result = new ArrayList<>();
                ret.iterator().forEachRemaining(((List<BasicDBObject>) result)::add);
                exchange1.getOut().setHeader(MongoDbConstants.RESULT_PAGE_SIZE, ((List<BasicDBObject>) result).size());
            } finally {
                ret.iterator().close();
            }
        } else {
            result = ret;
        }
        return result;
    };
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:57,代码来源:MongoDbProducer.java


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