How do I update a deeply nested field for all documents [duplicate]
This question already has an answer here:
How do I update Array Elements matching criteria in a MongoDB document?
1 answer
How to Update Multiple Array Elements in mongodb
10 answers
MongoDB : find value in Array with multiple criteria
1 answer
Environment: MEAN Technology Stack
How do I update all fields in all documents for a collection where targetProperty: "value199"
and objects targetObjId: 1. The value to update it to doesn't really matter.
MongoDB Document Layout:
"_id": 1,
"collection1": [
"targetObjId": 1,
"objA":
"prop1": "value1",
"targetProperty": "value199",
,
"targetObjId": 2,
"objA":
"prop1": "value1",
"targetProperty": "value2",
]
,
"_id" 2,
"collection1": [
"targetObjId": 1,
"objA":
"prop1": "value1",
"targetProperty": "value199",
,
]
,
...
As another illustration:

node.js mongodb
marked as duplicate by Neil Lunn
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Nov 14 '18 at 3:46
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
How do I update Array Elements matching criteria in a MongoDB document?
1 answer
How to Update Multiple Array Elements in mongodb
10 answers
MongoDB : find value in Array with multiple criteria
1 answer
Environment: MEAN Technology Stack
How do I update all fields in all documents for a collection where targetProperty: "value199"
and objects targetObjId: 1. The value to update it to doesn't really matter.
MongoDB Document Layout:
"_id": 1,
"collection1": [
"targetObjId": 1,
"objA":
"prop1": "value1",
"targetProperty": "value199",
,
"targetObjId": 2,
"objA":
"prop1": "value1",
"targetProperty": "value2",
]
,
"_id" 2,
"collection1": [
"targetObjId": 1,
"objA":
"prop1": "value1",
"targetProperty": "value199",
,
]
,
...
As another illustration:

node.js mongodb
marked as duplicate by Neil Lunn
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Nov 14 '18 at 3:46
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
.updateMany({ ""collection1": "$elemMatch": "targetObjId": 1, "objA.targetProperty": "value199" , "$set": "collection1.$.targetProperty": "value200" )if there was anything obtuse about the existing answers. Note also the "multiple array elements" answers just in case you decide that more than one object within each array needs updating. Your question only highlighted one, but just in case.
– Neil Lunn
Nov 14 '18 at 3:52
add a comment |
This question already has an answer here:
How do I update Array Elements matching criteria in a MongoDB document?
1 answer
How to Update Multiple Array Elements in mongodb
10 answers
MongoDB : find value in Array with multiple criteria
1 answer
Environment: MEAN Technology Stack
How do I update all fields in all documents for a collection where targetProperty: "value199"
and objects targetObjId: 1. The value to update it to doesn't really matter.
MongoDB Document Layout:
"_id": 1,
"collection1": [
"targetObjId": 1,
"objA":
"prop1": "value1",
"targetProperty": "value199",
,
"targetObjId": 2,
"objA":
"prop1": "value1",
"targetProperty": "value2",
]
,
"_id" 2,
"collection1": [
"targetObjId": 1,
"objA":
"prop1": "value1",
"targetProperty": "value199",
,
]
,
...
As another illustration:

node.js mongodb
This question already has an answer here:
How do I update Array Elements matching criteria in a MongoDB document?
1 answer
How to Update Multiple Array Elements in mongodb
10 answers
MongoDB : find value in Array with multiple criteria
1 answer
Environment: MEAN Technology Stack
How do I update all fields in all documents for a collection where targetProperty: "value199"
and objects targetObjId: 1. The value to update it to doesn't really matter.
MongoDB Document Layout:
"_id": 1,
"collection1": [
"targetObjId": 1,
"objA":
"prop1": "value1",
"targetProperty": "value199",
,
"targetObjId": 2,
"objA":
"prop1": "value1",
"targetProperty": "value2",
]
,
"_id" 2,
"collection1": [
"targetObjId": 1,
"objA":
"prop1": "value1",
"targetProperty": "value199",
,
]
,
...
As another illustration:

This question already has an answer here:
How do I update Array Elements matching criteria in a MongoDB document?
1 answer
How to Update Multiple Array Elements in mongodb
10 answers
MongoDB : find value in Array with multiple criteria
1 answer
node.js mongodb
node.js mongodb
edited Nov 17 '18 at 3:43
Rod
asked Nov 14 '18 at 3:33
RodRod
5,5701777136
5,5701777136
marked as duplicate by Neil Lunn
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Nov 14 '18 at 3:46
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by Neil Lunn
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Nov 14 '18 at 3:46
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
.updateMany({ ""collection1": "$elemMatch": "targetObjId": 1, "objA.targetProperty": "value199" , "$set": "collection1.$.targetProperty": "value200" )if there was anything obtuse about the existing answers. Note also the "multiple array elements" answers just in case you decide that more than one object within each array needs updating. Your question only highlighted one, but just in case.
– Neil Lunn
Nov 14 '18 at 3:52
add a comment |
.updateMany({ ""collection1": "$elemMatch": "targetObjId": 1, "objA.targetProperty": "value199" , "$set": "collection1.$.targetProperty": "value200" )if there was anything obtuse about the existing answers. Note also the "multiple array elements" answers just in case you decide that more than one object within each array needs updating. Your question only highlighted one, but just in case.
– Neil Lunn
Nov 14 '18 at 3:52
.updateMany({ ""collection1": "$elemMatch": "targetObjId": 1, "objA.targetProperty": "value199" , "$set": "collection1.$.targetProperty": "value200" ) if there was anything obtuse about the existing answers. Note also the "multiple array elements" answers just in case you decide that more than one object within each array needs updating. Your question only highlighted one, but just in case.– Neil Lunn
Nov 14 '18 at 3:52
.updateMany({ ""collection1": "$elemMatch": "targetObjId": 1, "objA.targetProperty": "value199" , "$set": "collection1.$.targetProperty": "value200" ) if there was anything obtuse about the existing answers. Note also the "multiple array elements" answers just in case you decide that more than one object within each array needs updating. Your question only highlighted one, but just in case.– Neil Lunn
Nov 14 '18 at 3:52
add a comment |
0
active
oldest
votes
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
.updateMany({ ""collection1": "$elemMatch": "targetObjId": 1, "objA.targetProperty": "value199" , "$set": "collection1.$.targetProperty": "value200" )if there was anything obtuse about the existing answers. Note also the "multiple array elements" answers just in case you decide that more than one object within each array needs updating. Your question only highlighted one, but just in case.– Neil Lunn
Nov 14 '18 at 3:52