spring-data-mongodb icon indicating copy to clipboard operation
spring-data-mongodb copied to clipboard

Upsert does not generate _class field in document [DATAMONGO-1362]

Open spring-projects-issues opened this issue 9 years ago • 5 comments

Remi Dettai opened DATAMONGO-1362 and commented

Upsert does not generate _class attribute event if entity class is specified.

The attached Spring Boot test demonstrates this. As you can see in the Robomongo screenshot, the document generated by this test does not have the _class field that is always added by Spring-Data-Mongodb when saving entities. It could (should?) be added though as the entity class is specified in the upsert method


Affects: 1.8.1 (Gosling SR1)

Attachments:

spring-projects-issues avatar Jan 18 '16 08:01 spring-projects-issues

Oliver Drotbohm commented

Can you please provide a little more context? What are you doing exactly? What's happening? What do you expect to see? Do you have an executable test case that shows the error?

spring-projects-issues avatar Jan 18 '16 09:01 spring-projects-issues

Remi Dettai commented

Hi! Sorry I did not provide any details. It was kind of rude from me. I believed my issue was obvious, but I know an issue is never obvious!!! I added a small Spring Boot poject with my test... you just need mongo running on localhost with no password for it to run. If you don't want to run it, you can just check the Robomongo screenshot also attached. Do yo need any further information?

spring-projects-issues avatar Jan 19 '16 04:01 spring-projects-issues

Remi Dettai commented

I added a Spring Boot test with a screenshot of the result

spring-projects-issues avatar Jan 19 '16 04:01 spring-projects-issues

Any updates on this issue? MongoTemplate.upsert still does not include the "_class" attribute. In ran into this issue when i tried to retrieve documents via myRepo.findAll(example, exampleMatcher). The call always returned 0 documents even with any constraint to any property cause the underlying query matches only documents with "_class" attribute equals to the persisted entity class.

laubfall avatar Sep 12 '22 13:09 laubfall

I've got the same issue. I don't get my entities back because they lack the _class field when calling 'findAll'. It would help a lot if this gets fixed. It causes some ugly workarounds.

ctschubel avatar Oct 06 '22 10:10 ctschubel

This is the expected behaviour. Update will not add the type hint within the root object as it is specifically targeting fields and not entire objects.

christophstrobl avatar Feb 24 '23 12:02 christophstrobl