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