MongoDB not emitting `before` for DELETE events

137 views
Skip to first unread message

Robin Tang

unread,
Mar 24, 2024, 2:35:23 PM3/24/24
to debezium
Hey team,

As the subject suggests, the MongoDB connector is not emitting a `before` object for deletes.

Version: Debezium 2.5
MongoDB: 5.0.14

My Debezium config (using Connect)
```
{
    "name": "mongodb-connector",
    "config": {
        "connector.class" : "io.debezium.connector.mongodb.MongoDbConnector",
        "tasks.max" : "1",
        "mongodb.connection.string" : "mongodb://mongodb:27017/?replicaSet=rs0",
        "topic.prefix" : "dbserver1",
        "mongodb.user" : "debezium",
        "mongodb.password" : "dbz",
        "mongodb.capture.mode": "change_streams_update_full_with_pre_image"
    }
}
```
^ I don't think capture.mode makes a difference here since this pertains to updates only, but added anyways. 


Using the example:
```
rs0:PRIMARY> db.customers.remove({"_id": 1001});
WriteResult({ "nRemoved" : 1 })
rs0:PRIMARY>
```

```
$ kafka-console-consumer --topic dbserver1.inventory.customers --bootstrap-server localhost:29092
{"schema":{"type":"struct","fields":[{"type":"string","optional":true,"name":"io.debezium.data.Json","version":1,"field":"before"},{"type":"string","optional":true,"name":"io.debezium.data.Json","version":1,"field":"after"},{"type":"struct","fields":[{"type":"array","items":{"type":"string","optional":false},"optional":true,"field":"removedFields"},{"type":"string","optional":true,"name":"io.debezium.data.Json","version":1,"field":"updatedFields"},{"type":"array","items":{"type":"struct","fields":[{"type":"string","optional":false,"field":"field"},{"type":"int32","optional":false,"field":"size"}],"optional":false,"name":"io.debezium.connector.mongodb.changestream.truncatedarray","version":1},"optional":true,"field":"truncatedArrays"}],"optional":true,"name":"io.debezium.connector.mongodb.changestream.updatedescription","version":1,"field":"updateDescription"},{"type":"struct","fields":[{"type":"string","optional":false,"field":"version"},{"type":"string","optional":false,"field":"connector"},{"type":"string","optional":false,"field":"name"},{"type":"int64","optional":false,"field":"ts_ms"},{"type":"string","optional":true,"name":"io.debezium.data.Enum","version":1,"parameters":{"allowed":"true,last,false,incremental"},"default":"false","field":"snapshot"},{"type":"string","optional":false,"field":"db"},{"type":"string","optional":true,"field":"sequence"},{"type":"string","optional":false,"field":"rs"},{"type":"string","optional":false,"field":"collection"},{"type":"int32","optional":false,"field":"ord"},{"type":"string","optional":true,"field":"lsid"},{"type":"int64","optional":true,"field":"txnNumber"},{"type":"int64","optional":true,"field":"wallTime"}],"optional":false,"name":"io.debezium.connector.mongo.Source","field":"source"},{"type":"string","optional":true,"field":"op"},{"type":"int64","optional":true,"field":"ts_ms"},{"type":"struct","fields":[{"type":"string","optional":false,"field":"id"},{"type":"int64","optional":false,"field":"total_order"},{"type":"int64","optional":false,"field":"data_collection_order"}],"optional":true,"name":"event.block","version":1,"field":"transaction"}],"optional":false,"name":"dbserver1.inventory.customers.Envelope"},"payload":{"before":null,"after":null,"updateDescription":null,"source":{"version":"2.5.3.Final","connector":"mongodb","name":"dbserver1","ts_ms":1711305148000,"snapshot":"false","db":"inventory","sequence":null,"rs":"rs0","collection":"customers","ord":1,"lsid":null,"txnNumber":null,"wallTime":null},"op":"d","ts_ms":1711305148854,"transaction":null}}
```

Thanks!
Robin

Robin Tang

unread,
May 6, 2024, 9:24:25 PM5/6/24
to debezium
Just want to bump this one up. I think the example listed here: https://debezium.io/documentation/reference/stable/connectors/mongodb.html#mongodb-delete-events is wrong as delete never emits `before`.

- Robin

Jakub Čecháček

unread,
May 7, 2024, 9:41:52 AM5/7/24
to debezium

Hi Robin,

the before field is populated from the fullDocumentBeforeChange filed which comes from Mongo's change event document received by Debezium from the database. The presence of this field requires that before image are enabled on database level for the watched collection. Please see the following references 

Regards,
Jakub.
Reply all
Reply to author
Forward
0 new messages