[SERVER-37276] Allow constant integer in $group clause Created: 23/Sep/18  Updated: 06/Dec/22

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

Type: New Feature Priority: Major - P3
Reporter: Renato Riccio Assignee: Backlog - Query Optimization
Resolution: Unresolved Votes: 0
Labels: mql-semantics
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Assigned Teams:
Query Optimization
Participants:

 Description   

Currently, $group does not allow to have a constant integer in a group clause, on the other hand, it supports strings. For example

db.foo.aggregate([{$group:{_id: {a:"$a", d:1},c: {$sum:"$c"}}}])
assert: command failed: {
    "ok" : 0,
    "errmsg" : "$group does not support inclusion-style expressions",
    "code" : 17390,
    "codeName" : "Location17390"
} : aggregate failed

If set d as a string we don't get any error

db.foo.aggregate([{$group:{_id: {a:"$a", d:"1"},c: {$sum:"$c"}}}])

In order to be consistent group should support also integer inside _id



 Comments   
Comment by Renato Riccio [ 24/Sep/18 ]

I confirm $literal it works as workaround:

db.foo.aggregate([{$group:{_id: {a:"$a", d:{$literal:1}},c: {$sum:"$c"}}}])

Comment by Asya Kamsky [ 24/Sep/18 ]

You can use $literal. But it’s a bit silly - we fixed it somewhere else I’m pretty sure.

Comment by Andy Schwerin [ 24/Sep/18 ]

Can you use {$literal:1}?

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