[SERVER-42116] Update with aggregation pipeline shows in oplog as replace operation Created: 09/Jul/19  Updated: 29/Oct/23  Resolved: 29/Oct/20

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: 4.2.0-rc2
Fix Version/s: None

Type: Improvement Priority: Major - P3
Reporter: Wan Bachtiar Assignee: Backlog - Query Execution
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
Assigned Teams:
Query Execution
Backwards Compatibility: Fully Compatible
Participants:

 Description   

Normal update operation in shows up in oplog (changestream) as operationType update, while update with aggregation pipeline shows up in oplog (changestream) as operationType replace.

Example:

db.test.update({a:1}, {$set:{b:"foo"}})

Output:

{   '_id': {   '_data': '...'},
    'clusterTime': Timestamp(1562633420, 1),
    'documentKey': {'_id': ObjectId('5d1ede84705cbd6a35d69fcf')},
    'ns': {'coll': 'test', 'db': 'test'},
    'operationType': 'update',
    'updateDescription': {'removedFields': [], 'updatedFields': {'b': 'foo'}}}

While update with aggregation:

db.test.update({a:1}, [{$set:{b:"bar"}}])

Output:

{   '_id': {   '_data': '...'},
    'clusterTime': Timestamp(1562633424, 1),
    'documentKey': {'_id': ObjectId('5d1ede84705cbd6a35d69fcf')},
    'fullDocument': {   '_id': ObjectId('5d1ede84705cbd6a35d69fcf'),
                        'a': 1.0,
                        'b': 'bar'},
    'ns': {'coll': 'test', 'db': 'test'},
    'operationType': 'replace'}

Would this behaviour likely to be changed in the future ?



 Comments   
Comment by Katya Kamenieva [ 29/Oct/20 ]

This behavior is changing in the next major release (5.0). With the motivation of making the oplog entries smaller, there will be a new format to show the diff with an indication of the new version `"$v" : 2` SERVER-47856.

Both modifier-style updates and updates with pipeline can produce a `replace` or `diff` entry in the oplog depending on which is smaller. This will also apply to the change streams messages, so to get an updated document, the option `full_document="updateLookup"` has to be used.

Generated at Thu Feb 08 04:59:38 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.