Skip to content

Commit 774a855

Browse files
committed
Ensure legacy replace queries aren't marked as collectible
JAVA-3151
1 parent 762108d commit 774a855

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

driver-core/src/main/com/mongodb/internal/connection/UpdateMessage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ protected EncodingMetadata encodeMessageBodyWithMetadata(final BsonOutput bsonOu
5555

5656
addDocument(updateRequest.getFilter(), bsonOutput, new NoOpFieldNameValidator());
5757
if (updateRequest.getType() == REPLACE) {
58-
addCollectibleDocument(updateRequest.getUpdate(), bsonOutput, new CollectibleDocumentFieldNameValidator());
58+
addDocument(updateRequest.getUpdate(), bsonOutput, new CollectibleDocumentFieldNameValidator());
5959
} else {
6060
int bufferPosition = bsonOutput.getPosition();
6161
addDocument(updateRequest.getUpdate(), bsonOutput, new UpdateFieldNameValidator());

driver-core/src/test/functional/com/mongodb/internal/connection/WriteProtocolCommandEventSpecification.groovy

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import spock.lang.Shared
3737

3838
import static com.mongodb.ClusterFixture.getPrimary
3939
import static com.mongodb.ClusterFixture.getSslSettings
40+
import static com.mongodb.bulk.WriteRequest.Type.REPLACE
4041
import static com.mongodb.bulk.WriteRequest.Type.UPDATE
4142
import static com.mongodb.connection.ConnectionFixture.getCredentialListWithCache
4243
import static com.mongodb.internal.connection.ProtocolTestHelper.execute
@@ -131,6 +132,42 @@ class WriteProtocolCommandEventSpecification extends OperationFunctionalSpecific
131132
async << [false, true]
132133
}
133134

135+
def 'should deliver started and completed command events for a replace'() {
136+
given:
137+
def filter = new BsonDocument('_id', new BsonInt32(1))
138+
def update = new BsonDocument('x', new BsonInt32(1))
139+
def updateRequest = new UpdateRequest(filter, update, REPLACE).multi(false).upsert(true)
140+
def protocol = new UpdateProtocol(getNamespace(), true, updateRequest)
141+
def commandListener = new TestCommandListener()
142+
protocol.commandListener = commandListener
143+
144+
when:
145+
execute(protocol, connection, async)
146+
147+
then:
148+
commandListener.eventsWereDelivered([new CommandStartedEvent(1, connection.getDescription(), getDatabaseName(), 'update',
149+
new BsonDocument('update', new BsonString(getCollectionName()))
150+
.append('ordered', BsonBoolean.TRUE)
151+
.append('writeConcern',
152+
new BsonDocument('w', new BsonInt32(0)))
153+
.append('updates', new BsonArray(
154+
[new BsonDocument('q', filter)
155+
.append('u', update)
156+
.append('upsert', BsonBoolean.TRUE)]))),
157+
new CommandSucceededEvent(1, connection.getDescription(), 'update',
158+
new BsonDocument('ok', new BsonInt32(1)), 0)])
159+
160+
cleanup:
161+
// force acknowledgement
162+
new CommandProtocolImpl(getDatabaseName(), new BsonDocument('drop', new BsonString(getCollectionName())),
163+
NO_OP_FIELD_NAME_VALIDATOR, ReadPreference.primary(), new BsonDocumentCodec())
164+
.sessionContext(NoOpSessionContext.INSTANCE)
165+
.execute(connection)
166+
167+
where:
168+
async << [false, true]
169+
}
170+
134171
def 'should deliver started and completed command events for a delete'() {
135172
given:
136173
def filter = new BsonDocument('_id', new BsonInt32(1))

0 commit comments

Comments
 (0)