{
id: 139234234,
count: 12,
type: apple,
buyer: alex,
}
When the buyer
got updated, I don’t want to receive the update information from changeStream
, is it possible ignore some of the fields when using change stream?
{
id: 139234234,
count: 12,
type: apple,
buyer: alex,
}
When the buyer
got updated, I don’t want to receive the update information from changeStream
, is it possible ignore some of the fields when using change stream?
The change stream watch accepts a pipeline filter as an argument, so you can do some thing like this:
db.collection.watch(
[
{
$match: {
operationType: "update",
"updateDescription.updatedFields.buyer": {
$exists: false
}
}
}
]
)
What if I want to ignore the field is buyer: [subdocument]
, the updateDescription is:
updateDescription: {
updatedFields: {
'buyer.2.name': "alex",
'buyer.2.price': 1.4,
'buyer.2.max': 12146,
}}
I want to ignore all the update&remove related to the buyer field. Thank you.
Can you give an example of the documents and the updates occurring on them?
Document example:
id: 139234234,
count: 12,
type: apple,
buyer: [{name: "peter", price: 1.23, max: 129},
{"alex", price: 1.4, "max": 12146}]
}
Updates occurring on it:
db.updateMany({ id: 139234234 }, [
{
$set: {
buyer: {
$concatArrays: [
{
$filter: {
input: "$buyer",
cond: {
{ $ne: ["$$this.name", "john"] },
},
},
},
[
{
name: "john",
price: 12,
max: 234,
},
],
],
},
},
},
]);
Is there anything you need from me? I want to ignore all updateFields
that starting with buyer
.
Are you wanting to ignore any updates that have buyer
in them or are you wanting any update not to include buyer
?
I want any update not to include buyer, although I will not update/delete buyer
with other field(both of them you mentioned will work for me in this case), I want to decrease the workload of change stream by not monitoring the buyer
field from update and delete.
May I have any update in here, thank you.
This could be as simple as:
db.collection.watch(
[
{
$project: {
"updateDescription.updatedFields.buyer": 0
}
}
]
)
By applying your solution, I will also receive the above update.