@@ -1753,6 +1753,122 @@ default long exactCount(Query query, String collectionName) {
17531753 */
17541754 <T > List <T > findAllAndRemove (Query query , Class <T > entityClass , String collectionName );
17551755
1756+ /**
1757+ * Triggers <a href="https://docs.mongodb.com/manual/reference/method/db.collection.replaceOne/">replaceOne</a> to
1758+ * replace a single document matching {@link Criteria} of given {@link Query} with the {@code replacement} document.
1759+ * <br />
1760+ * The collection name is derived from the {@literal replacement} type. <br />
1761+ * Options are defaulted to {@link ReplaceOptions#empty()}. <br />
1762+ * <strong>NOTE:</strong> The replacement entity must not hold an {@literal id}.
1763+ *
1764+ * @param query the {@link Query} class that specifies the {@link Criteria} used to find a record and also an optional
1765+ * fields specification. Must not be {@literal null}.
1766+ * @param replacement the replacement document. Must not be {@literal null}.
1767+ * @return the {@link UpdateResult} which lets you access the results of the previous replacement.
1768+ * @throws org.springframework.data.mapping.MappingException if the collection name cannot be
1769+ * {@link #getCollectionName(Class) derived} from the given replacement value.
1770+ */
1771+ default <T > UpdateResult replace (Query query , T replacement ) {
1772+ return replace (query , replacement , ReplaceOptions .empty ());
1773+ }
1774+
1775+ /**
1776+ * Triggers <a href="https://docs.mongodb.com/manual/reference/method/db.collection.replaceOne/">replaceOne</a> to
1777+ * replace a single document matching {@link Criteria} of given {@link Query} with the {@code replacement}
1778+ * document.<br />
1779+ * Options are defaulted to {@link ReplaceOptions#empty()}. <br />
1780+ * <strong>NOTE:</strong> The replacement entity must not hold an {@literal id}.
1781+ *
1782+ * @param query the {@link Query} class that specifies the {@link Criteria} used to find a record and also an optional
1783+ * fields specification. Must not be {@literal null}.
1784+ * @param replacement the replacement document. Must not be {@literal null}.
1785+ * @param collectionName the collection to query. Must not be {@literal null}.
1786+ * @return the {@link UpdateResult} which lets you access the results of the previous replacement.
1787+ * @throws org.springframework.data.mapping.MappingException if the collection name cannot be
1788+ * {@link #getCollectionName(Class) derived} from the given replacement value.
1789+ */
1790+ default <T > UpdateResult replace (Query query , T replacement , String collectionName ) {
1791+ return replace (query , replacement , ReplaceOptions .empty (), collectionName );
1792+ }
1793+
1794+ /**
1795+ * Triggers <a href="https://docs.mongodb.com/manual/reference/method/db.collection.replaceOne/">replaceOne</a> to
1796+ * replace a single document matching {@link Criteria} of given {@link Query} with the {@code replacement} document
1797+ * taking {@link ReplaceOptions} into account.<br />
1798+ * <strong>NOTE:</strong> The replacement entity must not hold an {@literal id}.
1799+ *
1800+ * @param query the {@link Query} class that specifies the {@link Criteria} used to find a record and also an optional
1801+ * fields specification. Must not be {@literal null}.
1802+ * @param replacement the replacement document. Must not be {@literal null}.
1803+ * @param options the {@link FindAndModifyOptions} holding additional information. Must not be {@literal null}.
1804+ * @return the {@link UpdateResult} which lets you access the results of the previous replacement.
1805+ * @throws org.springframework.data.mapping.MappingException if the collection name cannot be
1806+ * {@link #getCollectionName(Class) derived} from the given replacement value.
1807+ */
1808+ default <T > UpdateResult replace (Query query , T replacement , ReplaceOptions options ) {
1809+ return replace (query , replacement , options , getCollectionName (ClassUtils .getUserClass (replacement )));
1810+ }
1811+
1812+ /**
1813+ * Triggers <a href="https://docs.mongodb.com/manual/reference/method/db.collection.replaceOne/">replaceOne</a> to
1814+ * replace a single document matching {@link Criteria} of given {@link Query} with the {@code replacement} document
1815+ * taking {@link ReplaceOptions} into account.<br />
1816+ * <strong>NOTE:</strong> The replacement entity must not hold an {@literal id}.
1817+ *
1818+ * @param query the {@link Query} class that specifies the {@link Criteria} used to find a record and also an optional
1819+ * fields specification. Must not be {@literal null}.
1820+ * @param replacement the replacement document. Must not be {@literal null}.
1821+ * @param options the {@link FindAndModifyOptions} holding additional information. Must not be {@literal null}.
1822+ * @return the {@link UpdateResult} which lets you access the results of the previous replacement.
1823+ * @throws org.springframework.data.mapping.MappingException if the collection name cannot be
1824+ * {@link #getCollectionName(Class) derived} from the given replacement value.
1825+ */
1826+ default <T > UpdateResult replace (Query query , T replacement , ReplaceOptions options , String collectionName ) {
1827+
1828+ Assert .notNull (replacement , "Replacement must not be null" );
1829+ return replace (query , replacement , options , (Class <T >) ClassUtils .getUserClass (replacement ), collectionName );
1830+ }
1831+
1832+ /**
1833+ * Triggers <a href="https://docs.mongodb.com/manual/reference/method/db.collection.replaceOne/">replaceOne</a> to
1834+ * replace a single document matching {@link Criteria} of given {@link Query} with the {@code replacement} document
1835+ * taking {@link ReplaceOptions} into account.<br />
1836+ * <strong>NOTE:</strong> The replacement entity must not hold an {@literal id}.
1837+ *
1838+ * @param query the {@link Query} class that specifies the {@link Criteria} used to find a record and also an optional
1839+ * fields specification. Must not be {@literal null}.
1840+ * @param replacement the replacement document. Must not be {@literal null}.
1841+ * @param options the {@link FindAndModifyOptions} holding additional information. Must not be {@literal null}.
1842+ * @param entityType the type used for mapping the {@link Query} to domain type fields and deriving the collection
1843+ * from. Must not be {@literal null}.
1844+ * @return the {@link UpdateResult} which lets you access the results of the previous replacement.
1845+ * @throws org.springframework.data.mapping.MappingException if the collection name cannot be
1846+ * {@link #getCollectionName(Class) derived} from the given replacement value.
1847+ */
1848+ default <S > UpdateResult replace (Query query , S replacement , ReplaceOptions options , Class <S > entityType ) {
1849+
1850+ return replace (query , replacement , options , entityType , getCollectionName (ClassUtils .getUserClass (entityType )));
1851+ }
1852+
1853+ /**
1854+ * Triggers <a href="https://docs.mongodb.com/manual/reference/method/db.collection.replaceOne/">replaceOne</a> to
1855+ * replace a single document matching {@link Criteria} of given {@link Query} with the {@code replacement} document
1856+ * taking {@link ReplaceOptions} into account.<br />
1857+ * <strong>NOTE:</strong> The replacement entity must not hold an {@literal id}.
1858+ *
1859+ * @param query the {@link Query} class that specifies the {@link Criteria} used to find a record and also an optional
1860+ * fields specification. Must not be {@literal null}.
1861+ * @param replacement the replacement document. Must not be {@literal null}.
1862+ * @param options the {@link FindAndModifyOptions} holding additional information. Must not be {@literal null}.
1863+ * @param entityType the type used for mapping the {@link Query} to domain type fields. Must not be {@literal null}.
1864+ * @param collectionName the collection to query. Must not be {@literal null}.
1865+ * @return the {@link UpdateResult} which lets you access the results of the previous replacement.
1866+ * @throws org.springframework.data.mapping.MappingException if the collection name cannot be
1867+ * {@link #getCollectionName(Class) derived} from the given replacement value.
1868+ */
1869+ <S > UpdateResult replace (Query query , S replacement , ReplaceOptions options , Class <S > entityType ,
1870+ String collectionName );
1871+
17561872 /**
17571873 * Returns the underlying {@link MongoConverter}.
17581874 *
0 commit comments