I want to find all documents in collection my_collection, that contain the nested field “some.deep.field”, and unset that field. I am trying the following in mongosh (in Compass, Atlas):
First of all, I don’t how your query works, because the syntax is wrong and this will throw an error.
Check out the update with aggregation pipeline syntax from this documentation, it’s not really hard to understand.
The problem with your query:
You missed the query filter and directly passed the aggregation pipeline in the first argument.
The $match stage is not a supported stage in the update with aggregation pipeline, because you can filter by passing the query filter in the first argument same as a regular update query.
Ahh, this does not require an update with the aggregation pipeline, You can use a regular query with the $pull operator, because “field” is not a property it’s a value/element of an array.
[quote=“Victor_Grazi, post:6, topic:275486”]
Sorry, I transcribed it incorrectly, I am trying to remove a field from an object in an array. This is more accurate:
Sorry. I must have cut-n-past wrongly the first time. It is indeed valid JSON.
However, it does not match the description:
There is no object called deep. There is however a string value “deep” as the first element of the array. The field named field is one of the 2 fields of the second element of the array.
Sorry, transcription errors. This one is pretty close. I am trying to modify every collection that has
{“globalSearchConfig.aggregationStages.search.compound.should.autocomplete.fuzzy”:{$exists:true}}, to unset the field called “fuzzy” from any object called “autocomplete” in the “should” array that has it