Example usage for com.mongodb.client.model.changestream ChangeStreamDocument getNamespace

List of usage examples for com.mongodb.client.model.changestream ChangeStreamDocument getNamespace

Introduction

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

Prototype

@BsonIgnore
@Nullable
public MongoNamespace getNamespace() 

Source Link

Document

Returns the namespace, derived from the "ns" field in a change stream document.

Usage

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

License:Apache License

@Override
protected Message<ChangeStreamDocument<Document>, Object> createMessage(ChangeStreamDocument<Document> source,
        Class<Object> targetType, RequestOptions options) {

    // namespace might be null for eg. OperationType.INVALIDATE
    MongoNamespace namespace = Optional.ofNullable(source.getNamespace())
            .orElse(new MongoNamespace("unknown", options.getCollectionName()));

    return new ChangeStreamEventMessage<>(new ChangeStreamEvent<>(source, targetType, mongoConverter),
            MessageProperties.builder().databaseName(namespace.getDatabaseName())
                    .collectionName(namespace.getCollectionName()).build());
}