How to use MongoDB Panache simplified update query with multiple properties #26395
-
I'm using MongoDB Panache with the repository pattern and I'm trying to do an update setting multiple properties of a document with a single query. According to the MongoDB with Panache docs (e.g. https://quarkus.io/version/2.2/guides/mongodb-panache#simplified-queries ) it's possible to do so with a simplified query:
What I've tried doing is this (excerpt of my actual code): return update("state = ?1, participantId = ?2, lastUpdate = ?3",
AppointmentState.BOOKED, participantDto.getId(), dateTimeProvider.currentSystemTime())
.where("id = ?1 AND state = ?2 AND participantId is null",
new ObjectId(appointmentId), AppointmentState.FREE); But what this generates as real query against MongoDB is this:
Notice this part: The only thing that worked for me is to not use a simplified (update) query but instead write the actual MongoDB json query for the update: return update("{'$set' : {'state': ?1, 'participantId': ?2, 'lastUpdate': ?3}}",
AppointmentState.BOOKED, participantDto.getId(), dateTimeProvider.currentSystemTime())
.where("_id = ?1 AND state = ?2 AND participantId is null",
new ObjectId(appointmentId), AppointmentState.FREE); Which generates something like Did I do something wrong with the simplified query version or is this a bug? I've tried using Quarkus 2.0.3-Final and 2.2.3-Final. At least for now, I'm not able to upgrade to a more recent version due to other project dependencies. If that's an actual bug (and I'm not just missing something obvious), I would be happy to provide a pull request with possible solution. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
/cc @FroMage, @evanchooly, @loicmathieu |
Beta Was this translation helpful? Give feedback.
-
You should use
It's documented inside the JavaDoc that specify the update part as a Panache query, but the guide is incorrect about it https://quarkus.io/guides/mongodb-panache#simplified-queries so there is a bug in the guide. |
Beta Was this translation helpful? Give feedback.
You should use
and
and not,
in the update part:It's documented inside the JavaDoc that specify the update part as a Panache query, but the guide is incorrect about it https://quarkus.io/guides/mongodb-panache#simplified-queries so there is a bug in the guide.