Skip to content

Commit 3c004bd

Browse files
committed
Document createCollection(…) annotation usage.
1 parent 836ec6d commit 3c004bd

File tree

2 files changed

+32
-6
lines changed

2 files changed

+32
-6
lines changed

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoOperations.java

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -260,9 +260,21 @@ default SessionScoped withSession(Supplier<ClientSession> sessionProvider) {
260260

261261
/**
262262
* Create an uncapped collection with a name based on the provided entity class.
263+
* <p>
264+
* This method derives {@link CollectionOptions} from the given {@code entityClass} using
265+
* {@link org.springframework.data.mongodb.core.mapping.Document} and
266+
* {@link org.springframework.data.mongodb.core.mapping.TimeSeries} annotations to determine:
267+
* <ul>
268+
* <li>Collation</li>
269+
* <li>TimeSeries time and meta fields, granularity and {@code expireAfter}</li>
270+
* </ul>
271+
* Any other options such as change stream options, schema-based details (validation, encryption) are not considered
272+
* and must be provided through {@link #createCollection(Class, CollectionOptions)} or
273+
* {@link #createCollection(String, CollectionOptions)}.
263274
*
264275
* @param entityClass class that determines the collection to create.
265276
* @return the created collection.
277+
* @see #createCollection(Class, CollectionOptions)
266278
*/
267279
<T> MongoCollection<Document> createCollection(Class<T> entityClass);
268280

@@ -998,7 +1010,8 @@ default <T> List<T> findDistinct(Query query, String field, String collection, C
9981010
* @see Update
9991011
* @see AggregationUpdate
10001012
*/
1001-
<T> @Nullable T findAndModify(Query query, UpdateDefinition update, FindAndModifyOptions options, Class<T> entityClass);
1013+
<T> @Nullable T findAndModify(Query query, UpdateDefinition update, FindAndModifyOptions options,
1014+
Class<T> entityClass);
10021015

10031016
/**
10041017
* Triggers <a href="https://docs.mongodb.org/manual/reference/method/db.collection.findAndModify/">findAndModify </a>
@@ -1021,8 +1034,8 @@ default <T> List<T> findDistinct(Query query, String field, String collection, C
10211034
* @see Update
10221035
* @see AggregationUpdate
10231036
*/
1024-
<T> @Nullable T findAndModify(Query query, UpdateDefinition update, FindAndModifyOptions options, Class<T> entityClass,
1025-
String collectionName);
1037+
<T> @Nullable T findAndModify(Query query, UpdateDefinition update, FindAndModifyOptions options,
1038+
Class<T> entityClass, String collectionName);
10261039

10271040
/**
10281041
* Triggers
@@ -1102,7 +1115,8 @@ default <T> List<T> findDistinct(Query query, String field, String collection, C
11021115
* as it is after the update.
11031116
* @since 2.1
11041117
*/
1105-
default <T> @Nullable T findAndReplace(Query query, T replacement, FindAndReplaceOptions options, String collectionName) {
1118+
default <T> @Nullable T findAndReplace(Query query, T replacement, FindAndReplaceOptions options,
1119+
String collectionName) {
11061120

11071121
Assert.notNull(replacement, "Replacement must not be null");
11081122
return findAndReplace(query, replacement, options, (Class<T>) ClassUtils.getUserClass(replacement), collectionName);
@@ -1154,8 +1168,8 @@ default <T> List<T> findDistinct(Query query, String field, String collection, C
11541168
* {@link #getCollectionName(Class) derived} from the given replacement value.
11551169
* @since 2.1
11561170
*/
1157-
default <S, T> @Nullable T findAndReplace(Query query, S replacement, FindAndReplaceOptions options, Class<S> entityType,
1158-
Class<T> resultType) {
1171+
default <S, T> @Nullable T findAndReplace(Query query, S replacement, FindAndReplaceOptions options,
1172+
Class<S> entityType, Class<T> resultType) {
11591173

11601174
return findAndReplace(query, replacement, options, entityType,
11611175
getCollectionName(ClassUtils.getUserClass(entityType)), resultType);

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/ReactiveMongoOperations.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,21 @@ default ReactiveSessionScoped withSession(Supplier<ClientSession> sessionProvide
214214

215215
/**
216216
* Create an uncapped collection with a name based on the provided entity class.
217+
* <p>
218+
* This method derives {@link CollectionOptions} from the given {@code entityClass} using
219+
* {@link org.springframework.data.mongodb.core.mapping.Document} and
220+
* {@link org.springframework.data.mongodb.core.mapping.TimeSeries} annotations to determine:
221+
* <ul>
222+
* <li>Collation</li>
223+
* <li>TimeSeries time and meta fields, granularity and {@code expireAfter}</li>
224+
* </ul>
225+
* Any other options such as change stream options, schema-based details (validation, encryption) are not considered
226+
* and must be provided through {@link #createCollection(Class, CollectionOptions)} or
227+
* {@link #createCollection(String, CollectionOptions)}.
217228
*
218229
* @param entityClass class that determines the collection to create.
219230
* @return the created collection.
231+
* @see #createCollection(Class, CollectionOptions)
220232
*/
221233
<T> Mono<MongoCollection<Document>> createCollection(Class<T> entityClass);
222234

0 commit comments

Comments
 (0)