Example usage for com.mongodb.client FindIterable collation

List of usage examples for com.mongodb.client FindIterable collation

Introduction

In this page you can find the example usage for com.mongodb.client FindIterable collation.

Prototype

FindIterable<TResult> collation(@Nullable Collation collation);

Source Link

Document

Sets the collation options

A null value represents the server default.

Usage

From source file:org.springframework.data.mongodb.core.messaging.TailableCursorTask.java

License:Apache License

@Override
protected MongoCursor<Document> initCursor(MongoTemplate template, RequestOptions options,
        Class<?> targetType) {

    Document filter = new Document();
    Collation collation = null;//from w  w w  .  ja  v a 2s.  co  m

    if (options instanceof TailableCursorRequest.TailableCursorRequestOptions) {

        TailableCursorRequestOptions requestOptions = (TailableCursorRequestOptions) options;
        if (requestOptions.getQuery().isPresent()) {

            Query query = requestOptions.getQuery().get();

            filter.putAll(queryMapper.getMappedObject(query.getQueryObject(),
                    template.getConverter().getMappingContext().getPersistentEntity(
                            targetType.equals(Document.class) ? Object.class : targetType)));

            collation = query.getCollation()
                    .map(org.springframework.data.mongodb.core.query.Collation::toMongoCollation).orElse(null);
        }
    }

    FindIterable<Document> iterable = template.getCollection(options.getCollectionName()).find(filter)
            .cursorType(CursorType.TailableAwait).noCursorTimeout(true);

    if (collation != null) {
        iterable = iterable.collation(collation);
    }

    return iterable.iterator();
}