[SERVER-29406] syntactic sugars for aggregations Created: 31/May/17  Updated: 06/Dec/22  Resolved: 12/Jun/17

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

Type: New Feature Priority: Trivial - P5
Reporter: F?rat KÜÇÜK Assignee: Backlog - Query Team (Inactive)
Resolution: Won't Fix Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to SERVER-29971 Readable Aggregation Formulas Closed
Assigned Teams:
Query
Backwards Compatibility: Fully Compatible
Participants:

 Description   

IMHO writing aggregation for simple join operations are big efforts and some syntax improvements will be good. I know JSON has limitations and lots of stuff that I don't know about server core. But let me express my ideas:

For instance basic calculations and string concats:

db.collection.find({}, {_id: 1, name: 1, "nonExistField": {$statement: "1 + 4"}});

for just concatanation:

db.collection.find({}, {_id: 1, name: 1, "newField": {$concat: "$firstName + ' ' + $lastName"}});

or sum operations:

db.collection.find({}, {_id: 1, "total": {$sum: "$age"}});

and for join operations:

this is a sample User collection:

{
  "_id" : ObjectId("592e75ebe076c31cee205b72"),
  "name": "Test User",
  "tags": [
    DBRef("tag", ObjectId("592e75ebe076c31cee205b77")),
    DBRef("tag", ObjectId("592e75ebe076c31cee205b78"))
  ]
}

{
  'tags.$join': {'$elemMatch': {'name': {'$regex': '^test', '$options': 'i'}}}
}

Server can convert my query to an aggregation query but as a simple user It's a big effort.



 Comments   
Comment by Asya Kamsky [ 12/Jun/17 ]

The server does not seem to be the right place to solve the syntax problem. All aggregations sent to the server must still be in proper syntax, even when they are short for a more complex pipeline (example "$count" stage which is syntactic sugar for $group stage that just wants count).

It's been the purview of drivers and frameworks built on top of drivers to provide different syntax than what the server expects.

Comment by Asya Kamsky [ 09/Jun/17 ]

Is syntactic sugar better handled by drivers? Drivers already provide syntax that's "nicer" for end-user and translate it to appropriate server commands ...

Comment by F?rat KÜÇÜK [ 31/May/17 ]

Sorry for the typo in the title. I cannot edit my own issue.

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