public FindIterable<Document> doInCollection(MongoCollection<Document> collection) throws MongoException, DataAccessException { return collection.find(query, Document.class).projection(fields); } }
private Set<String> getTableMetadataNames(String schemaName) throws TableNotFoundException { MongoDatabase db = client.getDatabase(schemaName); MongoCursor<Document> cursor = db.getCollection(schemaCollection) .find().projection(new Document(TABLE_NAME_KEY, true)).iterator(); HashSet<String> names = new HashSet<>(); while (cursor.hasNext()) { names.add((cursor.next()).getString(TABLE_NAME_KEY)); } return names; }
private <T> boolean collectionIsEmpty(@Nullable final ClientSession clientSession, final MongoCollection<T> collection) { if (clientSession != null) { return collection.find(clientSession).projection(new Document("_id", 1)).first() == null; } else { return collection.find().projection(new Document("_id", 1)).first() == null; } }
public Document doInCollection(MongoCollection<Document> collection) throws MongoException, DataAccessException { FindIterable<Document> iterable = collection.find(query, Document.class); if (LOGGER.isDebugEnabled()) { LOGGER.debug("findOne using query: {} fields: {} in db.collection: {}", serializeToJsonSafely(query), serializeToJsonSafely(fields.orElseGet(Document::new)), collection.getNamespace() != null ? collection.getNamespace().getFullName() : "n/a"); } if (fields.isPresent()) { iterable = iterable.projection(fields.get()); } return iterable.first(); } }
projection.put(field, INCLUDE); findIterable.projection(projection);
@Signature public WrapMongoIterable projection(BasicDBObject projection) { if (getWrappedObject() instanceof FindIterable) { return new WrapMongoIterable(this.__env__, ((FindIterable) getWrappedObject()).projection(projection)); } else { return this; } }
public MongoCursor<Document> execute(MongoSplit split, List<MongoColumnHandle> columns) { Document output = new Document(); for (MongoColumnHandle column : columns) { output.append(column.getName(), 1); } MongoCollection<Document> collection = getCollection(split.getSchemaTableName()); FindIterable<Document> iterable = collection.find(buildQuery(split.getTupleDomain())).projection(output); if (cursorBatchSize != 0) { iterable.batchSize(cursorBatchSize); } return iterable.iterator(); }
projection.put(fieldName, INCLUDE); findIterable.projection(projection);
private Document findOne(Document query, Document projection) { MongoCollection col = controllerService.getDatabase(databaseName).getCollection(collection); MongoCursor<Document> it = (projection != null ? col.find(query).projection(projection) : col.find(query)).iterator(); Document retVal = it.hasNext() ? it.next() : null; it.close(); return retVal; } }
@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); } } });
@Override public CloseableIterator<T> doInCollection(MongoCollection<Document> collection) throws MongoException, DataAccessException { MongoPersistentEntity<?> persistentEntity = mappingContext.getRequiredPersistentEntity(entityType); Document mappedFields = getMappedFieldsObject(query.getFieldsObject(), persistentEntity, returnType); Document mappedQuery = queryMapper.getMappedObject(query.getQueryObject(), persistentEntity); FindIterable<Document> cursor = new QueryCursorPreparer(query, entityType) .prepare(collection.find(mappedQuery, Document.class).projection(mappedFields)); return new CloseableIterableCursorAdapter<>(cursor, exceptionTranslator, new ProjectingReadCallback<>(mongoConverter, entityType, returnType, collectionName)); } });
.prepare(collection.find(removeQuery).projection(MappedDocument.getIdOnlyProjection())) // .iterator();
public FindIterable<Document> doInCollection(MongoCollection<Document> collection) throws MongoException, DataAccessException { return collection.find(query, Document.class).projection(fields); } }
it.projection(projection);
find = find.projection(Document.parse(context.getProperty(PROJECTION).evaluateAttributeExpressions(input).getValue()));
@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); }
public Document doInCollection(MongoCollection<Document> collection) throws MongoException, DataAccessException { FindIterable<Document> iterable = collection.find(query, Document.class); if (LOGGER.isDebugEnabled()) { LOGGER.debug("findOne using query: {} fields: {} in db.collection: {}", serializeToJsonSafely(query), serializeToJsonSafely(fields.orElseGet(Document::new)), collection.getNamespace() != null ? collection.getNamespace().getFullName() : "n/a"); } if (fields.isPresent()) { iterable = iterable.projection(fields.get()); } return iterable.first(); } }
@Override public SessionData get(String sessionId) { Document doc = this.sessions .find(eq(SESSION_ID, sessionId)) .projection(include(SESSION_DATA)) .first(); if (doc == null) { return null; } String sessionStored = doc.getString(SESSION_DATA); SessionData sessionData = transcoder.decode(sessionStored); return sessionData; }
@Override public CloseableIterator<T> doInCollection(MongoCollection<Document> collection) throws MongoException, DataAccessException { MongoPersistentEntity<?> persistentEntity = mappingContext.getRequiredPersistentEntity(entityType); Document mappedFields = getMappedFieldsObject(query.getFieldsObject(), persistentEntity, returnType); Document mappedQuery = queryMapper.getMappedObject(query.getQueryObject(), persistentEntity); FindIterable<Document> cursor = new QueryCursorPreparer(query, entityType) .prepare(collection.find(mappedQuery, Document.class).projection(mappedFields)); return new CloseableIterableCursorAdapter<>(cursor, exceptionTranslator, new ProjectingReadCallback<>(mongoConverter, entityType, returnType, collectionName)); } });
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; }