How do I update a deeply nested field for all documents [duplicate]










0
















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:



enter image description here










share|improve this question















marked as duplicate by Neil Lunn mongodb
Users with the  mongodb badge can single-handedly close mongodb questions as duplicates and reopen them as needed.

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















0
















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:



enter image description here










share|improve this question















marked as duplicate by Neil Lunn mongodb
Users with the  mongodb badge can single-handedly close mongodb questions as duplicates and reopen them as needed.

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













0












0








0









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:



enter image description here










share|improve this question

















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:



enter image description here





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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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 mongodb
Users with the  mongodb badge can single-handedly close mongodb questions as duplicates and reopen them as needed.

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 mongodb
Users with the  mongodb badge can single-handedly close mongodb questions as duplicates and reopen them as needed.

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

















  • .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












0






active

oldest

votes

















0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes

Popular posts from this blog

27

Top Tejano songwriter Luis Silva dead of heart attack at 64

Category:Rhetoric