Example usage for com.mongodb.client.model.changestream FullDocument DEFAULT

List of usage examples for com.mongodb.client.model.changestream FullDocument DEFAULT

Introduction

In this page you can find the example usage for com.mongodb.client.model.changestream FullDocument DEFAULT.

Prototype

FullDocument DEFAULT

To view the source code for com.mongodb.client.model.changestream FullDocument DEFAULT.

Click Source Link

Document

Default

Returns the servers default value in the fullDocument field.

Usage

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

License:Apache License

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

    List<Document> filter = Collections.emptyList();
    BsonDocument resumeToken = new BsonDocument();
    Collation collation = null;//w ww .  j ava2 s . com
    FullDocument fullDocument = FullDocument.DEFAULT;

    if (options instanceof ChangeStreamRequest.ChangeStreamRequestOptions) {

        ChangeStreamOptions changeStreamOptions = ((ChangeStreamRequestOptions) options)
                .getChangeStreamOptions();
        filter = prepareFilter(template, changeStreamOptions);

        if (changeStreamOptions.getFilter().isPresent()) {

            Object val = changeStreamOptions.getFilter().get();
            if (val instanceof Aggregation) {
                collation = ((Aggregation) val).getOptions().getCollation()
                        .map(org.springframework.data.mongodb.core.query.Collation::toMongoCollation)
                        .orElse(null);
            }
        }

        if (changeStreamOptions.getResumeToken().isPresent()) {
            resumeToken = changeStreamOptions.getResumeToken().get().asDocument();
        }

        fullDocument = changeStreamOptions.getFullDocumentLookup()
                .orElseGet(() -> ClassUtils.isAssignable(Document.class, targetType) ? FullDocument.DEFAULT
                        : FullDocument.UPDATE_LOOKUP);
    }

    ChangeStreamIterable<Document> iterable = filter.isEmpty()
            ? template.getCollection(options.getCollectionName()).watch(Document.class)
            : template.getCollection(options.getCollectionName()).watch(filter, Document.class);

    if (!resumeToken.isEmpty()) {
        iterable = iterable.resumeAfter(resumeToken);
    }

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

    iterable = iterable.fullDocument(fullDocument);

    return iterable.iterator();
}