@@ -22,28 +22,67 @@ public interface __className__Repository
2222 OptimizedMongoDownstreamRepository<__className__>,
2323 MongoHistoryRepository<__className__, __idType__> {
2424
25- /*
26- * EXAMPLE REPOSITORY METHODS
27- *
28- * // Find by field using auto-generated query
29- * List<__className__> findAllBySomeFieldGreaterThan(Long value);
30- *
31- * // Custom query for fields that are explicit
32- * @Query("{ 'someField': ?0 }")
33- * List<__className__> findBySomeField(String value);
34- *
35- * // Custom aggregation
36- * @Aggregation(pipeline = {
37- * "{ '$match': { 'someField': ?0 } }",
38- * "{ '$group': { '_id': null, 'average': { '$avg': '$numericField' } } }"
39- * })
40- * List<Document> findAverageBySomeField(String value);
41- *
42- * // Simple efficient update without reading whole document
43- * @Query("{ 'id' : ?0 }")
44- * @Update("{ '$inc' : { 'counter' : ?1 } }")
45- * void incrementCounter(__idType__ id, int increment);
46- */
25+
26+ /*
27+ * =====================================================================
28+ * SPRING DATA MONGODB REPOSITORY QUERY EXAMPLES
29+ * =====================================================================
30+ *
31+ * These examples demonstrate the various ways to define queries in a
32+ * Spring Data MongoDB repository interface. Replace the placeholder
33+ * names with your actual field names and types.
34+ *
35+ * Terminology:
36+ * - FieldA, FieldB : Top-level fields on the document
37+ * - SubObject : A nested/embedded document
38+ * - SubObject.FieldA : A field within the nested document
39+ *
40+ * ---------------------------------------------------------------------
41+ * 1. AUTOMATICALLY DERIVED QUERIES
42+ * ---------------------------------------------------------------------
43+ * Spring Data parses the method name to generate the query.
44+ *
45+ * // Find where a top-level numeric field exceeds a threshold
46+ * List<MyDocument> findByFieldAGreaterThan(Long value);
47+ *
48+ * // Find by two fields within a nested subdocument (AND)
49+ * List<MyDocument> findBySubObjectFieldAAndSubObjectFieldB(
50+ * String fieldAValue, String fieldBValue);
51+ *
52+ * ---------------------------------------------------------------------
53+ * 2. ANNOTATION-BASED AGGREGATION
54+ * ---------------------------------------------------------------------
55+ * Use @Aggregation for pipelines such as $group, $project, $unwind.
56+ * Returns Document when the result shape differs from the entity.
57+ *
58+ * @Aggregation(pipeline = {
59+ * "{ '$match': { 'subObject.fieldA': ?0 } }",
60+ * "{ '$group': { '_id': null, 'averageFieldB': { '$avg': '$subObject.fieldB' } } }"
61+ * })
62+ * List<Document> findAverageFieldBByFieldA(String fieldAValue);
63+ *
64+ * ---------------------------------------------------------------------
65+ * 3. ANNOTATION-BASED UPDATE (WITHOUT FULL DOCUMENT READ/WRITE)
66+ * ---------------------------------------------------------------------
67+ * Combines @Query to match and @Update to modify in place.
68+ * Efficient for targeted field updates; bypasses entity serialisation.
69+ *
70+ * @Query("{ 'fieldA': ?0 }")
71+ * @Update("{ '$inc': { 'fieldB': ?1 } }")
72+ * void adjustFieldB(Long fieldAValue, int increment);
73+ *
74+ * ---------------------------------------------------------------------
75+ * 4. @Query WITH MONGODB QUERY LANGUAGE (MQL)
76+ * ---------------------------------------------------------------------
77+ * Gives access to the full range of MQL operators while still
78+ * binding method parameters positionally.
79+ *
80+ * @Query("{ 'subObject.fieldA': ?0, 'subObject.fieldB': ?1 }")
81+ * List<MyDocument> findBySubObjectFieldAAndFieldB(
82+ * String fieldAValue, String fieldBValue);
83+ *
84+ * =====================================================================
85+ */
4786
4887 // Streaming version for large result sets
4988 Stream<__className__> findAllBy();
0 commit comments