You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Panache Update query on MongoEntity is not working as expected.
Expected behavior
The YourMongoEntity should be updated for the given fields and the method should return the value of 1L (because only one document should match with _id value).
Actual behavior
java.lang.IllegalArgumentException: All update operators must start with '$', but 'someField' does not
at org.bson.AbstractBsonWriter.writeName(AbstractBsonWriter.java:535)
at com.mongodb.internal.connection.BsonWriterDecorator.writeName(BsonWriterDecorator.java:196)
at org.bson.codecs.DocumentCodec.encode(DocumentCodec.java:163)
at org.bson.codecs.DocumentCodec.encode(DocumentCodec.java:44)
at org.bson.codecs.BsonDocumentWrapperCodec.encode(BsonDocumentWrapperCodec.java:63)
at org.bson.codecs.BsonDocumentWrapperCodec.encode(BsonDocumentWrapperCodec.java:29)
at com.mongodb.internal.connection.SplittablePayload$WriteRequestEncoder.encode(SplittablePayload.java:216)
at com.mongodb.internal.connection.SplittablePayload$WriteRequestEncoder.encode(SplittablePayload.java:182)
at org.bson.codecs.BsonDocumentWrapperCodec.encode(BsonDocumentWrapperCodec.java:63)
at org.bson.codecs.BsonDocumentWrapperCodec.encode(BsonDocumentWrapperCodec.java:29)
at com.mongodb.internal.connection.BsonWriterHelper.writeDocument(BsonWriterHelper.java:77)
at com.mongodb.internal.connection.BsonWriterHelper.writePayload(BsonWriterHelper.java:59)
at com.mongodb.internal.connection.CommandMessage.encodeMessageBodyWithMetadata(CommandMessage.java:162)
at com.mongodb.internal.connection.RequestMessage.encode(RequestMessage.java:136)
at com.mongodb.internal.connection.CommandMessage.encode(CommandMessage.java:59)
at com.mongodb.internal.connection.InternalStreamConnection.sendAndReceive(InternalStreamConnection.java:360)
at com.mongodb.internal.connection.UsageTrackingInternalConnection.sendAndReceive(UsageTrackingInternalConnection.java:114)
at com.mongodb.internal.connection.DefaultConnectionPool$PooledConnection.sendAndReceive(DefaultConnectionPool.java:765)
at com.mongodb.internal.connection.CommandProtocolImpl.execute(CommandProtocolImpl.java:76)
at com.mongodb.internal.connection.DefaultServer$DefaultServerProtocolExecutor.execute(DefaultServer.java:209)
at com.mongodb.internal.connection.DefaultServerConnection.executeProtocol(DefaultServerConnection.java:115)
at com.mongodb.internal.connection.DefaultServerConnection.command(DefaultServerConnection.java:83)
at com.mongodb.internal.connection.DefaultServer$OperationCountTrackingConnection.command(DefaultServer.java:307)
at com.mongodb.internal.operation.MixedBulkWriteOperation.executeCommand(MixedBulkWriteOperation.java:395)
at com.mongodb.internal.operation.MixedBulkWriteOperation.executeBulkWriteBatch(MixedBulkWriteOperation.java:259)
at com.mongodb.internal.operation.MixedBulkWriteOperation.lambda$execute$2(MixedBulkWriteOperation.java:203)
at com.mongodb.internal.operation.SyncOperationHelper.lambda$withSourceAndConnection$0(SyncOperationHelper.java:127)
at com.mongodb.internal.operation.SyncOperationHelper.withSuppliedResource(SyncOperationHelper.java:152)
at com.mongodb.internal.operation.SyncOperationHelper.lambda$withSourceAndConnection$1(SyncOperationHelper.java:126)
at com.mongodb.internal.operation.SyncOperationHelper.withSuppliedResource(SyncOperationHelper.java:152)
at com.mongodb.internal.operation.SyncOperationHelper.withSourceAndConnection(SyncOperationHelper.java:125)
at com.mongodb.internal.operation.MixedBulkWriteOperation.lambda$execute$3(MixedBulkWriteOperation.java:188)
at com.mongodb.internal.operation.MixedBulkWriteOperation.lambda$decorateWriteWithRetries$0(MixedBulkWriteOperation.java:146)
at com.mongodb.internal.async.function.RetryingSyncSupplier.get(RetryingSyncSupplier.java:67)
at com.mongodb.internal.operation.MixedBulkWriteOperation.execute(MixedBulkWriteOperation.java:207)
at com.mongodb.internal.operation.MixedBulkWriteOperation.execute(MixedBulkWriteOperation.java:77)
at com.mongodb.client.internal.MongoClientDelegate$DelegateOperationExecutor.execute(MongoClientDelegate.java:173)
at com.mongodb.client.internal.MongoCollectionImpl.executeSingleWriteRequest(MongoCollectionImpl.java:1085)
at com.mongodb.client.internal.MongoCollectionImpl.executeUpdate(MongoCollectionImpl.java:1069)
at com.mongodb.client.internal.MongoCollectionImpl.updateMany(MongoCollectionImpl.java:632)
at com.mongodb.client.internal.MongoCollectionImpl.updateMany(MongoCollectionImpl.java:627)
at io.quarkus.mongodb.panache.common.runtime.PanacheUpdateImpl.executeUpdate(PanacheUpdateImpl.java:61)
at io.quarkus.mongodb.panache.common.runtime.PanacheUpdateImpl.where(PanacheUpdateImpl.java:34)
How to Reproduce?
Try the following:
DocumentupdDocument = newDocument("somefield", someValue);
YourMongoEntity.update(updDocument)
.where("_id = ?1", newObjectId(id)); // tried using "id" instead of "_id" or .where(new Document(....)) but still didn't work
@anamak9 there are two ways to update entities in MongodDB with Panache:
By updating the entity object: you update the field then call myEntity.update(). This mandates that you have an instance of your entity at hand (loaded for ex via findById).
By using an update query.
Here, you want to do a single update by the ID of a document by using an update query which is more performant if you don't have an instance of your entity but less easy / idiomatic.
Maybe the documentation is not very clear but when you use MyEntity.update(Document).where(...) the document must be an update document (something like {$set: {myField: myValue}} as this is not very easy to use MongoDB with Panache provides a simplified DSL what is called PanacheQL.
Describe the bug
Panache Update query on MongoEntity is not working as expected.
Expected behavior
The YourMongoEntity should be updated for the given fields and the method should return the value of 1L (because only one document should match with _id value).
Actual behavior
How to Reproduce?
Try the following:
Output of
uname -a
orver
No response
Output of
java -version
Java version: 21.0.1, vendor: Oracle Corporation, runtime: /usr/lib/jvm/jdk-21-oracle-x64
Quarkus version or git rev
3.0.3.Final
Build tool (ie. output of
mvnw --version
orgradlew --version
)Apache Maven 3.9.5 (57804ffe001d7215b5e7bcb531cf83df38f93546)
Additional information
No response
The text was updated successfully, but these errors were encountered: