[SERVER-37459] $group with $$ROOT returns error Created: 03/Oct/18  Updated: 29/Oct/23  Resolved: 09/Oct/18

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

Type: Bug Priority: Major - P3
Reporter: Robert Stam Assignee: Ian Boros
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
is depended on by CSHARP-2407 Reenable tests temporarily disabled u... Closed
Related
is related to SERVER-9507 Optimize $sort+$group+$first pipeline... Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Steps To Reproduce:

Repro usingĀ 4.1.3-231-ga106c80c19:

> db.version()
4.1.3-231-ga106c80c19
> db.test.find()
{ "_id" : 1, "x" : 1 }
{ "_id" : 2, "x" : 2 }
> db.test.aggregate([ { $group : { _id : "$$ROOT" } } ])
2018-10-03T14:24:20.951-0400 E QUERY    [js] Error: command failed: {
        "ok" : 0,
        "errmsg" : "FieldPath::tail() called on single element path",
        "code" : 16409,
        "codeName" : "Location16409"
} : aggregate failed :
_getErrorWithCode@src/mongo/shell/utils.js:25:13
doassert@src/mongo/shell/assert.js:18:14
_assertCommandWorked@src/mongo/shell/assert.js:534:17
assert.commandWorked@src/mongo/shell/assert.js:618:16
DB.prototype._runAggregate@src/mongo/shell/db.js:260:9
DBCollection.prototype.aggregate@src/mongo/shell/collection.js:1056:12
@(shell):1:1
>

Sprint: Query 2018-10-22
Participants:

 Description   

$group with $$ROOT starting failing recently when running the C# driver tests.

Not sure when exactly it started failing, but it can be reproduced usingĀ 4.1.3-231-ga106c80c19.

Here's a repro showing it working in 4.0.2:

> db.version()
4.0.2
> db.test.find()
{ "_id" : 1, "x" : 1 }
{ "_id" : 2, "x" : 2 }
> db.test.aggregate([ { $group : { _id : "$$ROOT" } } ])
{ "_id" : { "_id" : 2, "x" : 2 } }
{ "_id" : { "_id" : 1, "x" : 1 } }
>



 Comments   
Comment by Githook User [ 09/Oct/18 ]

Author:

{'name': 'Ian Boros', 'email': 'ian.boros@10gen.com'}

Message: SERVER-37459 special case for $group with $$ROOT or $$CURRENT
Branch: master
https://github.com/mongodb/mongo/commit/627d6027b15b2355cb9621dd28cce4b7024fbf9c

Comment by David Storch [ 03/Oct/18 ]

Thanks rstam! I believe this is a regression due to the changes for SERVER-9507. I'm assigning to justin.seyster to implement a fix.

Comment by Robert Stam [ 03/Oct/18 ]

I realize that this particular use of $group is a bit odd since all the documents (and therefore $$ROOT) will already be unique by virtue of the _id being unique.

This query was generated by the C# driver as part of a LINQ test. Even if it seems a bit odd, it still should work (as it did in 4.0.2).

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