Document createCollection(…) annotation usage.

Update documentation.

Closes: #4978
Original Pull Request: #4979
This commit is contained in:
Mark Paluch
2025-05-19 14:32:01 +02:00
committed by Christoph Strobl
parent d7ff6b1b66
commit 172a7d1940
5 changed files with 37 additions and 11 deletions

View File

@@ -260,9 +260,21 @@ public interface MongoOperations extends FluentMongoOperations {
/**
* Create an uncapped collection with a name based on the provided entity class.
* <p>
* This method derives {@link CollectionOptions} from the given {@code entityClass} using
* {@link org.springframework.data.mongodb.core.mapping.Document} and
* {@link org.springframework.data.mongodb.core.mapping.TimeSeries} annotations to determine:
* <ul>
* <li>Collation</li>
* <li>TimeSeries time and meta fields, granularity and {@code expireAfter}</li>
* </ul>
* Any other options such as change stream options, schema-based details (validation, encryption) are not considered
* and must be provided through {@link #createCollection(Class, CollectionOptions)} or
* {@link #createCollection(String, CollectionOptions)}.
*
* @param entityClass class that determines the collection to create.
* @return the created collection.
* @see #createCollection(Class, CollectionOptions)
*/
<T> MongoCollection<Document> createCollection(Class<T> entityClass);
@@ -998,7 +1010,8 @@ public interface MongoOperations extends FluentMongoOperations {
* @see Update
* @see AggregationUpdate
*/
<T> @Nullable T findAndModify(Query query, UpdateDefinition update, FindAndModifyOptions options, Class<T> entityClass);
<T> @Nullable T findAndModify(Query query, UpdateDefinition update, FindAndModifyOptions options,
Class<T> entityClass);
/**
* Triggers <a href="https://docs.mongodb.org/manual/reference/method/db.collection.findAndModify/">findAndModify </a>
@@ -1021,8 +1034,8 @@ public interface MongoOperations extends FluentMongoOperations {
* @see Update
* @see AggregationUpdate
*/
<T> @Nullable T findAndModify(Query query, UpdateDefinition update, FindAndModifyOptions options, Class<T> entityClass,
String collectionName);
<T> @Nullable T findAndModify(Query query, UpdateDefinition update, FindAndModifyOptions options,
Class<T> entityClass, String collectionName);
/**
* Triggers
@@ -1102,7 +1115,8 @@ public interface MongoOperations extends FluentMongoOperations {
* as it is after the update.
* @since 2.1
*/
default <T> @Nullable T findAndReplace(Query query, T replacement, FindAndReplaceOptions options, String collectionName) {
default <T> @Nullable T findAndReplace(Query query, T replacement, FindAndReplaceOptions options,
String collectionName) {
Assert.notNull(replacement, "Replacement must not be null");
return findAndReplace(query, replacement, options, (Class<T>) ClassUtils.getUserClass(replacement), collectionName);
@@ -1154,8 +1168,8 @@ public interface MongoOperations extends FluentMongoOperations {
* {@link #getCollectionName(Class) derived} from the given replacement value.
* @since 2.1
*/
default <S, T> @Nullable T findAndReplace(Query query, S replacement, FindAndReplaceOptions options, Class<S> entityType,
Class<T> resultType) {
default <S, T> @Nullable T findAndReplace(Query query, S replacement, FindAndReplaceOptions options,
Class<S> entityType, Class<T> resultType) {
return findAndReplace(query, replacement, options, entityType,
getCollectionName(ClassUtils.getUserClass(entityType)), resultType);

View File

@@ -214,9 +214,21 @@ public interface ReactiveMongoOperations extends ReactiveFluentMongoOperations {
/**
* Create an uncapped collection with a name based on the provided entity class.
* <p>
* This method derives {@link CollectionOptions} from the given {@code entityClass} using
* {@link org.springframework.data.mongodb.core.mapping.Document} and
* {@link org.springframework.data.mongodb.core.mapping.TimeSeries} annotations to determine:
* <ul>
* <li>Collation</li>
* <li>TimeSeries time and meta fields, granularity and {@code expireAfter}</li>
* </ul>
* Any other options such as change stream options, schema-based details (validation, encryption) are not considered
* and must be provided through {@link #createCollection(Class, CollectionOptions)} or
* {@link #createCollection(String, CollectionOptions)}.
*
* @param entityClass class that determines the collection to create.
* @return the created collection.
* @see #createCollection(Class, CollectionOptions)
*/
<T> Mono<MongoCollection<Document>> createCollection(Class<T> entityClass);

View File

@@ -42,8 +42,8 @@ public @interface Document {
/**
* The collection the document representing the entity is supposed to be stored in. If not configured, a default
* collection name will be derived from the type's name. The attribute supports SpEL expressions to dynamically
* calculate the collection to based on a per operation basis.
*
* calculate the collection to based on a per-operation basis.
*
* @return the name of the collection to be used.
*/
@AliasFor("collection")
@@ -53,7 +53,7 @@ public @interface Document {
* The collection the document representing the entity is supposed to be stored in. If not configured, a default
* collection name will be derived from the type's name. The attribute supports SpEL expressions to dynamically
* calculate the collection to based on a per operation basis.
*
*
* @return the name of the collection to be used.
*/
@AliasFor("value")

View File

@@ -41,7 +41,7 @@ public @interface TimeSeries {
/**
* The collection the document representing the entity is supposed to be stored in. If not configured, a default
* collection name will be derived from the type's name. The attribute supports SpEL expressions to dynamically
* calculate the collection based on a per operation basis.
* calculate the collection based on a per-operation basis.
*
* @return the name of the collection to be used.
* @see Document#collection()

View File

@@ -188,7 +188,7 @@ It is possible to create custom annotations out of the provided ones.
MongoDB Collection Info::
+
====
[source,java,indent=0,subs="verbatim,quotes",role="thrid"]
[source,json,indent=0,subs="verbatim,quotes",role="thrid"]
----
{
name: 'patient',