Skip to content

Commit 172a7d1

Browse files
mp911dechristophstrobl
authored andcommitted
Document createCollection(…) annotation usage.
Update documentation. Closes: #4978 Original Pull Request: #4979
1 parent d7ff6b1 commit 172a7d1

File tree

5 files changed

+37
-11
lines changed

5 files changed

+37
-11
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

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@
4242
/**
4343
* The collection the document representing the entity is supposed to be stored in. If not configured, a default
4444
* collection name will be derived from the type's name. The attribute supports SpEL expressions to dynamically
45-
* calculate the collection to based on a per operation basis.
46-
*
45+
* calculate the collection to based on a per-operation basis.
46+
*
4747
* @return the name of the collection to be used.
4848
*/
4949
@AliasFor("collection")
@@ -53,7 +53,7 @@
5353
* The collection the document representing the entity is supposed to be stored in. If not configured, a default
5454
* collection name will be derived from the type's name. The attribute supports SpEL expressions to dynamically
5555
* calculate the collection to based on a per operation basis.
56-
*
56+
*
5757
* @return the name of the collection to be used.
5858
*/
5959
@AliasFor("value")

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
/**
4242
* The collection the document representing the entity is supposed to be stored in. If not configured, a default
4343
* collection name will be derived from the type's name. The attribute supports SpEL expressions to dynamically
44-
* calculate the collection based on a per operation basis.
44+
* calculate the collection based on a per-operation basis.
4545
*
4646
* @return the name of the collection to be used.
4747
* @see Document#collection()

src/main/antora/modules/ROOT/pages/mongodb/mongo-encryption.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ It is possible to create custom annotations out of the provided ones.
188188
MongoDB Collection Info::
189189
+
190190
====
191-
[source,java,indent=0,subs="verbatim,quotes",role="thrid"]
191+
[source,json,indent=0,subs="verbatim,quotes",role="thrid"]
192192
----
193193
{
194194
name: 'patient',

0 commit comments

Comments
 (0)