[SERVER-14164] MongoDB: Too many positional (i.e. '$') elements found in path Created: 04/Jun/14  Updated: 10/Dec/14  Resolved: 02/Jul/14

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

Type: Bug Priority: Major - P3
Reporter: Jeff Whelpley Assignee: Thomas Rueckstiess
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-831 Positional Operator Matching Nested A... Closed
Operating System: ALL
Steps To Reproduce:

Run this query:

db.post.update(

{ 'answers.comments.name': 'jeff' }

,
{ '$set': {
'answers.$.comments.$.name': 'joe'
}},

{ multi: true }

)

Participants:

 Description   

I just upgraded to Mongo 2.6.1 and one update statement that was working before is not returning an error. The update statement is:

db.post.update( { 'answers.comments.name': 'jeff' },
    { '$set': {
        'answers.$.comments.$.name': 'joe'
    }},
    { multi: true }
)

The error I get is:

WriteResult({
    "nMatched" : 0,
    "nUpserted" : 0,
    "nModified" : 0,
    "writeError" : {
        "code" : 2,
        "errmsg" : "Too many positional (i.e. '$') elements found in path 'answers.$.comments.$.createUsername'"
    }
})

When I update an element just one level deep instead of two (i.e. answers.$.name instead of answers.$.comments.$.name), it works fine. If I downgrade my mongo instance below 2.6, it also works fine.



 Comments   
Comment by Jeff Whelpley [ 07/Jul/14 ]

Sorry for not getting back to me. I was wrong before. multiple positional elements never worked. I will just wait for the feature. Thanks!

Comment by Thomas Rueckstiess [ 02/Jul/14 ]

Hi Jeff,

I haven't heard back from you so I'm assuming this is no longer an issue. Please watch SERVER-831 for any progress on the requested feature.

Regards,
Thomas

Comment by Thomas Rueckstiess [ 10/Jun/14 ]

Hi Jeff,

The feature you're requesting (i.e. multiple $ placeholders for nested arrays) is not currently implemented in MongoDB. There is an open feature request SERVER-831.

From your description it sounds like you were able to run this query on a version below 2.6. This should not be possible. I tried reproducing this on 2.4.10, and got an error (as expected).

I generated some random data that I think matches your schema (please correct if wrong). Can you let me know if you notice any differences to what you did?

MongoDB shell version: 2.4.10
connecting to: test
> db.version()
2.4.10
> db.post.findOne()
{
	"_id" : ObjectId("53976b31fe4dceb71f3c5657"),
	"answers" : [
		{
			"text" : "2j1uqDE96HnLY5EeJ5WeU9vvRGFKgBBn613aVd7PD5PK2j2XBO",
			"comments" : [
				{
					"name" : "mathias",
					"number" : 69
				},
				{
					"name" : "tom",
					"number" : 13
				},
				{
					"name" : "spencer",
					"number" : 6
				}
			]
		},
		{
			"text" : "mTNUk5deNzvqLuujhds4MGgAR1uktOmEpGeCvDXXv7nYvRsVSU",
			"comments" : [
				{
					"name" : "spencer",
					"number" : 20
				},
				{
					"name" : "jeff",
					"number" : 16
				},
				{
					"name" : "mathias",
					"number" : 12
				}
			]
		},
		{
			"text" : "6dDFDIrrogJSI3F5hak7ZFFex9TG5spyxmaxw7NEwccEV9sTpN",
			"comments" : [
				{
					"name" : "andreas",
					"number" : 96
				},
				{
					"name" : "tom",
					"number" : 67
				},
				{
					"name" : "andreas",
					"number" : 8
				}
			]
		}
	]
}
> db.post.update({"answers.comments.name": "tom"}, {"$set": {"answers.$.comments.$.name": "joe"}}, {"multi": true})
Cannot apply the positional operator without a corresponding query field containing an array.

Regards,
Thomas

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