-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update with $unset fails with mapping exception #4565
Comments
@csmager thanks for reporting! We'll see what we can do about this. |
@csmager I might be missing something as I was not able to reproduce the issue on 4.0.x nor current main. |
Of course - I'd been a little lazy and hoped it'd be easily reproducible. I'll try and reproduce. |
The repo is here: https://github.com/csmager/spring-data-mongodb-repro But I suspect all you need is this. It appears the field mapping to @SpringBootTest
class SpringDataMongoDbReproTest {
@Autowired
private MongoTemplate mongoTemplate;
@Test
void throws_on_unset() {
this.mongoTemplate.updateMulti(
new Query(),
new Update()
.unset("field"),
Entity.class
);
}
public static class Entity {
private ObjectId id;
@Field(targetType = FieldType.DECIMAL128)
private BigDecimal field;
}
} |
ah thanks - I was using |
Yeah, it does seem it's the type hint / mapping that's causing it, it's probably quite a niche issue. |
Unfortunately there's no easy fix for the issue as we'd need to provide more context to the update mapping (which needs a bit more thought) to decide if conversion needs to be applied. |
I'm using spring-data-mongodb 4.0.8. On creating an update with an
$unset
, the following is added to the document:The value here - 1 - is then attempted to be mapped to the correct type for that field. In my case, that's
Decimal128
. I get this stack trace:The value here does not relate to the field value, it should not be mapped. My current workaround is to override
unset
as below:The mapping does not fail with an empty string, and an empty string is what's used in the examples in the docs.
The text was updated successfully, but these errors were encountered: