[SERVER-21794] Array field limitation in query document [Only one array field may appear in the query document.] Created: 08/Dec/15  Updated: 02/Feb/16  Resolved: 02/Feb/16

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

Type: New Feature Priority: Minor - P4
Reporter: efkan turen Assignee: Unassigned
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-18500 Resolve ambiguity of positional proje... Backlog
Related
related to SERVER-14662 Positional projection queries (and po... Closed
Participants:

 Description   

Hello,

Related page: https://docs.mongodb.org/manual/reference/operator/projection/positional/#array-field-limitation

Actually I can figure it out why this limitation is present. The issue might be regarding other operations. Especially `update`.

Is there any possibility of adding a new feature which providing usage of the second array field in the query document as a new feature in the feature?
(maybe by using sub-operator like `$arr1` and `$arr2`)

It seems as a private issue. However, cannot perform two-phase commits if an array value would be updated.

For instance;

	var query = { 
		_id: t.customer_id, 
		invoices: { $elemMatch: { 'year': t.year, 'month': t.month } }
	        pendingTransactions: t._id
	}
	var update = {
		'invoices.$.amount': 549,
		$push: { pendingTransactions: t._id }
	}
	db.customers.update(query, update)



 Comments   
Comment by J Rassi [ 02/Feb/16 ]

I am closing this ticket as a duplicate of SERVER-18500. When SERVER-18500 is implemented, then the match step will associate the array offset 2 with the "invoices" array, and will associate the array offset 1 with the "pendingTransactions" array. As a result, the positional operator will correctly translate the "invoices.$.amount" path in the update to "invoices.2.amount". Please feel free to add yourself as a watcher to SERVER-18500.

Note also that SERVER-14662 (which is currently scheduled to be completed before SERVER-18500) will fail positional projections and positional updates with an error, if the value of the positional operator is ambiguous. See that ticket for further details.

Comment by efkan turen [ 14/Dec/15 ]

Hi anonymous.user,

When $push operator is used, everything is OK. The problem is occurred when $pull operator is used. So, please consider

$pull: { pendingTransactions: t._id }

code instead of

$push: { pendingTransactions: t._id }

. It had to be $pull operator (It's my fault).

Related operation: https://docs.mongodb.org/v3.0/tutorial/perform-two-phase-commits/#update-both-accounts-list-of-pending-transactions

Best regards.

Comment by Kelsey Schubert [ 14/Dec/15 ]

Hi efkan_turen@yahoo.com,

Thank you for the detailed example. I've set the fixVersion to "Needs Triage" for this new feature to be considered in the next round of planning. Updates will be posted on this ticket as they happen.

Kind regards,
Thomas

Comment by efkan turen [ 09/Dec/15 ]

I'm writing down a fictitious document.

	{
	    _id : ObjectId("8a71dedaa8cbbf30154f14bc"), 
	    name: "Example LLC",
 	    invoices: [
    	        {
 	               year: 2015, 
 	               month: 6,
 	               amount: 461.4
   	         }, 
   	         {
 	               year: 2015, 
 	               month: 7,
 	               amount: 373
   	         },
   	         {
  	               year: 2015, 
  	              month: 8,
  	              amount: 522
   	         }
    	    ],
    	    pendingTransactions: ["42","38","27"]
	}

For updating the document using two-phase commits, the code that is in my first post should be used.
However the code has two array fields in the query phrase. They are invoices and pendingTransactions fields and MongoDB doesn't allow to this usage.
And this issue is a big problem when using the two-phase commit.

Edit:

Some additional informations;

As you might imagine, if my transaction _id is 38, year is 2015, month is 8 and amount is 8888 then the document would be like the below after updating;

	{
	    _id : ObjectId("8a71dedaa8cbbf30154f14bc"), 
	    name: "Example LLC",
 	    invoices: [
    	        {
 	               year: 2015, 
 	               month: 6,
 	               amount: 461.4
   	         }, 
   	         {
 	               year: 2015, 
 	               month: 7,
 	               amount: 8888
   	         },
   	         {
  	               year: 2015, 
  	              month: 8,
  	              amount: 522
   	         }
    	    ],
    	    pendingTransactions: ["42","38","27"]
	}

The reason is that the latest position of the positional operator would be 1 because of the 38 value at the second place. And thanks to positional operator place, the month 7 would be updated instead of month 8. Because month 7 in the second place.

Comment by Ramon Fernandez Marina [ 09/Dec/15 ]

efkan, can you also send us a sample document from your customers database? I'm not sure I'm seeing the whole picture here.

Thanks,
Ramón.

Generated at Thu Feb 08 03:58:27 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.