Update sub-document or attributes with query
See original GitHub issueHi, I’m trying to update some attributes with a custom query, but I get the following exception :
exception
com.couchbase.client.core.error.InvalidArgumentException: Unsupported type for JSON value: class com.rbleuse.spring.reactive.couchbase.model.Person
at com.couchbase.client.core.error.InvalidArgumentException.fromMessage(InvalidArgumentException.java:28) ~[core-io-2.3.4.jar:na]
Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException:
Error has been observed at the following site(s):
*__checkpoint ⇢ org.springframework.boot.actuate.metrics.web.reactive.server.MetricsWebFilter [DefaultWebFilterChain]
*__checkpoint ⇢ HTTP PUT "/classroom" [ExceptionHandlingWebHandler]
Original Stack Trace:
at com.couchbase.client.core.error.InvalidArgumentException.fromMessage(InvalidArgumentException.java:28) ~[core-io-2.3.4.jar:na]
at com.couchbase.client.java.json.JsonValue.coerce(JsonValue.java:94) ~[java-client-3.3.4.jar:na]
at com.couchbase.client.java.json.JsonArray.add(JsonArray.java:178) ~[java-client-3.3.4.jar:na]
at org.springframework.data.couchbase.repository.query.StringBasedN1qlQueryParser.putPositionalValue(StringBasedN1qlQueryParser.java:495) ~[spring-data-couchbase-4.4.3.jar:4.4.3]
at org.springframework.data.couchbase.repository.query.StringBasedN1qlQueryParser.getPositionalPlaceholderValues(StringBasedN1qlQueryParser.java:437) ~[spring-data-couchbase-4.4.3.jar:4.4.3]
at org.springframework.data.couchbase.repository.query.StringBasedN1qlQueryParser.getPlaceholderValues(StringBasedN1qlQueryParser.java:486) ~[spring-data-couchbase-4.4.3.jar:4.4.3]
at org.springframework.data.couchbase.core.query.StringQuery.toN1qlSelectString(StringQuery.java:80) ~[spring-data-couchbase-4.4.3.jar:4.4.3]
Here is my document :
@Document
@Scope("dev")
@Collection("classroom")
data class Classroom(
@field:Id
val id: String,
@field:Field
val person: Person,
@field:Field
val roomNumber: String
)
Here is my Person :
data class Person(
@field:Field
val firstName: String,
@field:Field
val lastName: String
)
And here is my query :
@Query("""
UPDATE #{#n1ql.bucket} c
USE KEYS $1 SET
c.person = $2
WHERE c.#{#n1ql.filter}""")
fun updateClassroom(id: String, person: Person)
It seems that the sdk requires a json object, so the only workaround I can think of is converting my Person with the MappingCouchbaseConverter.write(source, target)
which will convert with correct field names and types.
But this is an ugly solution, as the converter requires an id
attribute else it’ll throw An ID property is needed, but not found
- Is that possible to update some of my document attributes without manually convert my parameters ?
- Is there any other elegant solution ?
Issue Analytics
- State:
- Created a year ago
- Comments:13 (5 by maintainers)
Top Results From Across the Web
MongoDB update a subdocument attribute - Stack Overflow
What I need to do is to close the existing address record with an end attribute, and add a new line for the...
Read more >[Solved]-Update subdocument MongoDB-mongodb
Answer - use dot notation instead: $updater['tools.T1.T2_MODULE']=$update_array;. wrightee 86. Source: stackoverflow.com ...
Read more >Update nested sub Document with a specific condition
I want to update all subdocument “productIdealConsumption” which productId is “2895” with given document “skus”. My query given me error ...
Read more >Update multiple attributes within Array and Nested Array
I am using .NET Couchbase SDK and Sub-document API in application. To achieve the same via SDK, I can use Upsert/Replace method but...
Read more >Mongoose v6.8.0: SubDocuments
Note that populated documents are not subdocuments in Mongoose. Subdocument data is embedded in the top-level document. Referenced documents are separate top- ...
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 Free
Top 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
The enhancement would be to handle arbitrary (entity) objects as parameters, convert them to json using
Edit: this is actually an omission in parameter handling. It needs to handle not only simple types, but also collections and non-Simple types (like Person).
The change also includes a fix to handle lists of non-simple types (original would give NPE for non-simple lists for both named and ordered parameters).