[SERVER-6198] $group aggregate field names can contain dots, may cause problems with sharding Created: 25/Jun/12  Updated: 29/Aug/12  Resolved: 27/Jul/12

Status: Closed
Project: Core Server
Component/s: Aggregation Framework
Affects Version/s: None
Fix Version/s: 2.2.0-rc1

Type: Bug Priority: Major - P3
Reporter: Aaron Staple Assignee: Matt Dannenberg
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Operating System: ALL
Participants:

 Description   

Observed behavior: It is possible to create a $group aggregate field with a field name containing a dot.
Expected behavior: No dots allowed, uassert instead.

I think the dots might cause a problem when a group merger on mongos attempts to access fields set in the mongod results, but I haven't tested that specifically.

Test:

c = db.c;
c.drop();
 
c.save( { a:2 } );
c.save( { a:1 } );
 
printjson( c.aggregate( { $group:{ _id:0, 'z.x':{ $push:'$a' } } } ) );

Result:

{
	"result" : [
		{
			"_id" : 0,
			"z.x" : [
				2,
				1
			]
		}
	],
	"ok" : 1
}



 Comments   
Comment by auto [ 27/Jul/12 ]

Author:

{u'date': u'2012-07-23T07:34:09-07:00', u'email': u'dannenberg.matt@gmail.com', u'name': u'Matt Dannenberg'}

Message: SERVER-6198 disallow dotted field names in $group
Branch: master
https://github.com/mongodb/mongo/commit/a7258d30d840c0dd030922b4a521a779fc039514

Comment by auto [ 20/Jul/12 ]

Author:

{u'date': u'2012-07-14T12:04:12-07:00', u'email': u'mathias@10gen.com', u'name': u'Mathias Stearn'}

Message: Rewrite ExpressionObject

The main difference between this version and the old is that the following
three $pipelines will produce the same output (SERVER-6468):

{'a.b': 1}

// classic inclusion
{a:

{b: 1}

// nested inclusion

{'a.b': '$a.b'}

// dotted FieldPathExpression
{a:

{b: '$a.b'}

// nested FieldPathExpression

Additionally support for exclusion of fields other than _id has been
removed for 2.2 (SERVER-6361)

Other related bugs:
SERVER-6177 better error for

{a:1, 'a.b':1}

SERVER-6181 support for computed _id
SERVER-6184 support {'a.b': 1, a:{c:1}} in either order

Remaining TODOs:
Re-enable the isSimple() method
See if this can be used more directly by $group to support nested fields (SERVER-6198)

Disabled test for SERVER-5369 because it depends on ability to exclude
arbitrary fields.
Branch: master
https://github.com/mongodb/mongo/commit/ec18db98680d31b120350ad45d5f74095125e9a5

Comment by Mathias Stearn [ 20/Jul/12 ]

For now just assert !str::contains(fieldName, '.') and fieldName[0] != '$'. If we chose to support nesting we can do that later.

Comment by Mathias Stearn [ 03/Jul/12 ]

Ideally that should probably produce {z:{x:[2,1]}}, but that may depend on SERVER-6184

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