[SERVER-38399] Deep nested document not updated Created: 04/Dec/18  Updated: 01/Feb/19  Resolved: 01/Feb/19

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

Type: Bug Priority: Major - P3
Reporter: samba Assignee: Danny Hatcher (Inactive)
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Participants:

 Description   

db.coll.update({}, {$set: {"a.$[i].c.$[j].d": 2}}, {arrayFilters: [{"i.b": 0}, {"j.d": 0}]})

Input:

{a : [ { b : 0, c : [ { d : 0 }, { d : 1 } ] }, { b : 1, c : [ { d : 0 }, { d : 1 } ] } ] }

Output:

{a : [ { b : 0, c : [ { d : 2 }, { d : 1 } ] }, { b : 1, c : [ { d : 0 }, { d : 1 } ] } ] }



 Comments   
Comment by Danny Hatcher (Inactive) [ 01/Feb/19 ]

Hello,

We haven’t heard back from you for some time, so I’m going to mark this ticket as resolved. If this is still an issue for you, please provide additional information and we will reopen the ticket.

Thank you,

Danny

Comment by Danny Hatcher (Inactive) [ 05/Dec/18 ]

Hello,

The query as written can be understood as:

1. Look inside the array of "a"
2. Where the value of "b" is 0
3. Look deeper inside the same document inside the array of "c"
4. Where the value of "d" is 0
5. Set the value of "d" to 2.

Items 1-4 have to evaluate to "true" in order for step 5 to occur. We can see this happen correctly in the output. The array document that has "b" equal to 1 does not change value as it fails the first arrayFilter specified.

Before:

{
	"_id" : ObjectId("5c0836db936404687a41d5bf"),
	"a" : [
		{
			"b" : 0,
			"c" : [
				{
					"d" : 0
				},
				{
					"d" : 1
				}
			]
		},
		{
			"b" : 1,
			"c" : [
				{
					"d" : 0
				},
				{
					"d" : 1
				}
			]
		}
	]
}

After:

{
	"_id" : ObjectId("5c0836db936404687a41d5bf"),
	"a" : [
		{
			"b" : 0,
			"c" : [
				{
					"d" : 2
				},
				{
					"d" : 1
				}
			]
		},
		{
			"b" : 1,
			"c" : [
				{
					"d" : 0
				},
				{
					"d" : 1
				}
			]
		}
	]
}

For more information, please read our documentation on specifying arrayFilters for array update operations.

Does this address your issue?

Danny

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