[SERVER-35719] how to update element in array using different update document Created: 21/Jun/18  Updated: 23/Jul/18  Resolved: 21/Jun/18

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: 3.6.5
Fix Version/s: None

Type: Question Priority: Major - P3
Reporter: jipeng Assignee: Nick Brewer
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Participants:

 Description   

suppose the document below:

{{}}

//  
{
     itemList:[
		{id:20,num:12},
		{id:1,num:10},
		{id:2,num:12},
		{id:12,num:12}],
     flowerId:0
}

{{}}

how did i update the element with id =1 to make its num decrease 2 and the element with id =2 to make its num decrease 3 in a single statement?



 Comments   
Comment by Nick Brewer [ 21/Jun/18 ]

Thanks for your report. Please note that the SERVER project is for reporting bugs or feature suggestions for the MongoDB server. For MongoDB-related support discussion please post on the mongodb-user group or Stack Overflow with the mongodb tag. A question like this involving more discussion would be best posted on the mongodb-user group.

I'd suggest taking a look at the arrayFilters section within the db.collections.updateOne documentation, as well as the $inc operator, which can be used to increment numeric values by a set amount.

Regards,
Nick

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