deleteById() / deleteAll() not working with indexed properties
See original GitHub issueI have found another bug which prevents me from switching from fongo
to mongo-java-server
.
If you modify an indexed property of a document and then delete the document, no new document can be inserted with the value of the originally indexed property.
Here is a test case to reproduce the problem:
@RunWith(SpringRunner.class)
@SpringBootTest(classes={Issue.TestConfiguration.class})
public class Issue {
@Autowired private TestRepository repository;
@Test
public void testDeleteWithUniqueIndexes() throws Exception {
TestEntity document = repository.save(new TestEntity("DOC_1", "Text1"));
// update value of indexed property
document.setText("Text1 (updated)");
repository.save(document);
// delete document (deleteAll() does not work either)
repository.deleteById("DOC_1");
// duplicate key error
repository.save(new TestEntity("DOC_1", "Text1"));
}
@Configuration
@EnableMongoRepositories(basePackageClasses={TestRepository.class})
protected static class TestConfiguration {
@Bean
public MongoTemplate mongoTemplate(MongoClient mongoClient) {
return new MongoTemplate(mongoDbFactory(mongoClient));
}
@Bean
public MongoDbFactory mongoDbFactory(MongoClient mongoClient) {
return new SimpleMongoDbFactory(mongoClient, "test");
}
@Bean(destroyMethod="shutdown")
public MongoServer mongoServer() {
MongoServer mongoServer = new MongoServer(new MemoryBackend());
mongoServer.bind();
return mongoServer;
}
@Bean(destroyMethod="close")
public MongoClient mongoClient(MongoServer mongoServer) {
return new MongoClient(new ServerAddress(mongoServer.getLocalAddress()));
}
}
}
@Document(collection="test")
public class TestEntity {
@Id private String id;
@Indexed(unique=true) private String text;
public TestEntity() {
}
public TestEntity(String id, String text) {
this.id = id;
this.text = text;
}
public String getId() {
return id;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
}
public interface TestRepository extends MongoRepository<TestEntity, String> {
}
Issue Analytics
- State:
- Created 5 years ago
- Comments:8 (8 by maintainers)
Top Results From Across the Web
JPA Query to deleteById for a Composite Key declared using ...
MyIdClass. Use setObject() with an explicit Types value to specify the type to use. after seeing the actual query generated for a batch...
Read more >CrudRepository (Spring Data Core 3.0.0 API)
Deletes a given entity. void. deleteAll(). Deletes all entities managed by the repository. void.
Read more >Spring Data JPA CrudRepository delete() and deleteAll()
In Spring Data JPA Repository is top-level interface in hierarchy. Here we are going to see delete() and deleteAll() method of CrudRepository.
Read more >org.springframework.data.jpa.repository.support ... - Tabnine
notNull(entities, "The given Iterable of entities not be null! ... @Transactional @Override public void deleteAll() { for (T element : findAll()) ...
Read more >ReactorCrudRepository (javadoc 2.4.0 API) - GitHub Pages
Deletes a given entity. reactor.core.publisher.Mono<java.lang.Long>, deleteAll(). Deletes all entities managed by the repository.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
It’s caused by missing support for sparse indices. I’m currently working on it and hope to get it pushed soon.
That’s great to hear 😀
I’ve just released version
1.11.0