Add support for creating Time Series collection.

Introduce time series to CollectionOptions and add dedicated TimeSeries annotation to derive values from.

Closes #3731
Original pull request: #3732.
This commit is contained in:
Christoph Strobl
2021-07-15 09:52:50 +02:00
committed by Mark Paluch
parent f38f6d67ab
commit bacbd7133e
12 changed files with 547 additions and 20 deletions

View File

@@ -5,6 +5,7 @@
== What's New in Spring Data MongoDB 3.3
* Extended support for <<mapping-usage.document-references, referencing>> entities.
* Support for <<time-series, Time Series>> collections.
* Include/exclude `null` properties on write to `Document` through `@Field(write=…)`.
* Support for <<mapping-usage-indexes.wildcard-index>>.

View File

@@ -3382,3 +3382,4 @@ class GridFsClient {
include::tailable-cursors.adoc[]
include::change-streams.adoc[]
include::time-series.adoc[]

View File

@@ -0,0 +1,45 @@
[[time-series]]
== Time Series
MongoDB 5.0 introduced https://docs.mongodb.com/manual/core/timeseries-collections/[Time Series] collections optimized to efficiently store sequences of measurements.
Those collections need to be actively created before inserting any data. This can be done by manually executing the command, defining time series collection options or extracting options from a `@TimeSeries` annotation as shown in the examples below.
.Create a Time Series Collection
====
.Create a Time Series via the MongoDB Driver
[code, java]
----
template.execute(db -> {
com.mongodb.client.model.CreateCollectionOptions options = new CreateCollectionOptions();
options.timeSeriesOptions(new TimeSeriesOptions("timestamp"));
db.createCollection("weather", options);
return "OK";
});
----
.Create a Time Series Collection with CollectionOptions
[code, java]
----
template.createCollection("weather", CollectionOptions.timeSeries("timestamp"));
----
.Create a Time Series Collection derived from an Annotation
[code, java]
----
@TimeSeries(collection="weather", timeField = "timestamp")
public class Measurement {
String id;
Instant timestamp;
// ...
}
template.createCollection(Measurement.class);
----
====
The snippets above can easily be transferred to the reactive API offering the very same methods.
Just make sure to _subscribe_.