@Override public GridFSFindIterable limit(final int limit) { underlying.limit(limit); return this; }
/** * Obtain the current position of the oplog, and record it in the source. */ protected void recordCurrentOplogPosition() { primaryClient.execute("get oplog position", primary -> { MongoCollection<Document> oplog = primary.getDatabase("local").getCollection("oplog.rs"); Document last = oplog.find().sort(new Document("$natural", -1)).limit(1).first(); // may be null source.offsetStructForEvent(replicaSet.replicaSetName(), last); }); }
@Signature public WrapMongoIterable limit(int c) { if (getWrappedObject() instanceof FindIterable) { return new WrapMongoIterable(this.__env__, ((FindIterable) getWrappedObject()).limit(c)); } else { return this; } }
collection.find(query).sort(sort).limit(recordcount);
MongoCursor<Document> cursor = null; try { cursor = collection.find().limit(batchSize).iterator(); for (; cursor.hasNext(); length++) { Document document = cursor.next();
Document firstEvent = oplog.find().sort(new Document("$natural", 1)).limit(1).first(); // may be null return SourceInfo.extractEventTimestamp(firstEvent); });
@SuppressWarnings("resource") @Override public List<T> call() throws Exception { @Nullable Bson query = criteria != null ? convertToBson(criteria) : null; FindIterable<T> cursor = collection().find(query); if (!exclusion.isNil()) { cursor.projection(convertToBson(exclusion)); } if (!ordering.isNil()) { cursor.sort(convertToBson(ordering)); } cursor.skip(skip); if (limit != 0) { cursor.limit(limit); if (limit <= LARGE_BATCH_SIZE) { // if limit specified and is smaller than reasonable large batch size // then we force batch size to be the same as limit, // but negative, this force cursor to close right after result is sent cursor.batchSize(-limit); } } // close properly try (MongoCursor<T> iterator = cursor.iterator()) { return ImmutableList.copyOf(iterator); } } });
cursorToUse = cursorToUse.limit(query.getLimit());
it.limit(context.getProperty(LIMIT).evaluateAttributeExpressions(input).asInteger());
find = find.limit(context.getProperty(LIMIT).evaluateAttributeExpressions(input).asInteger());
@Override public Stream<Map<String, Object>> all(Map<String, Object> query, Long skip, Long limit) { FindIterable<Document> documents = query == null ? collection.find() : collection.find(new Document(query)); if (skip != 0) documents = documents.skip(skip.intValue()); if (limit != 0) documents = documents.limit(limit.intValue()); return asStream(documents); }
@Override public Stream<Map<String, Object>> find(Map<String, Object> query, Map<String, Object> project, Map<String, Object> sort, Long skip, Long limit) { FindIterable<Document> documents = query == null ? collection.find() : collection.find(new Document(query)); if (project != null) documents = documents.projection(new Document(project)); if (sort != null) documents = documents.sort(new Document(sort)); if (skip != 0) documents = documents.skip(skip.intValue()); if (limit != 0) documents = documents.limit(limit.intValue()); return asStream(documents); }
@Override public GridFSFindIterable limit(final int limit) { underlying.limit(limit); return this; }
private MongoCollectionResult find(MongoQueryOptions mongoQueryOptions, final MongoCollectionResult mongoCollectionResult, com.mongodb.client.MongoCollection<Document> collection) { Document filter = mongoQueryOptions.getFilter(); Document projection = mongoQueryOptions.getProjection(); Document sort = mongoQueryOptions.getSort(); FindIterable<Document> cursor = collection.find(filter); if (!MongoQueryOptions.EMPTY_DOCUMENT.equals(projection)) { cursor.projection(projection); } if (!MongoQueryOptions.EMPTY_DOCUMENT.equals(sort)) { cursor.sort(sort); } int resultLimit = mongoQueryOptions.getResultLimit(); if (resultLimit > 0) { cursor.limit(resultLimit); } cursor.forEach((Block<Document>) mongoCollectionResult::add); return mongoCollectionResult; }
cursorToUse = cursorToUse.limit(query.getLimit());
@Nonnull public Optional<ProjectEntityCrudKitSettings> findOne(@Nonnull ProjectId projectId) { return Optional.ofNullable(collection.find(withProjectId(projectId)) .limit(1).first()) .map(converter::fromDocument); }
private FindIterable<Document> applyQueryParams(FindIterable<Document> findIterable, Optional<QueryParams> queryParams) { if (queryParams.isPresent()) { QueryParams params = queryParams.get(); findIterable = findIterable .limit(params.limit()) .skip(params.skip()); } return findIterable; }
public boolean containsProject(@Nonnull ProjectId projectId) { return collection .find(withProjectId(projectId)) .projection(new Document()) .limit(1) .first() != null; }
public Optional<UserRecord> findOneByEmailAddress(String emailAddress) { Document firstDocument = collection .find(byEmailAddress(emailAddress)) .limit(1) .first(); return Optional.ofNullable(firstDocument).map(d -> converter.fromDocument(d)); }
public List<UserId> findByUserIdContainingIgnoreCase(String match, int limit) { FindIterable<Document> documents = collection .find(byUserIdContainsIgnoreCase(match)) .projection(withUserId()) .limit(limit); List<UserId> result = new ArrayList<>(limit); documents.map(d -> converter.getUserId(d)).into(result); return result; }