[DOCS-10022] Docs for SERVER-27614: provide aggregation expression to remove field: $$REMOVE Created: 22/Mar/17  Updated: 11/Aug/17  Resolved: 24/Jul/17

Status: Closed
Project: Documentation
Component/s: Server
Affects Version/s: None
Fix Version/s: mongodb-3.6, 3.5.5

Type: Task Priority: Major - P3
Reporter: Emily Hall Assignee: Kay Kim (Inactive)
Resolution: Done Votes: 0
Labels: expression, neweng, usability
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Documented
documents SERVER-27614 provide aggregation expression to rem... Closed
Participants:
Days since reply: 6 years, 29 weeks, 2 days ago
Epic Link: DOCS: 3.6 Server

 Description   

Documentation Request Summary:

Add docs for the new REMOVE variable here: https://docs.mongodb.com/manual/reference/aggregation-variables/.

Engineering Ticket Description:

The $project stage supports both inclusion and exclusion based projections. However, there is no way to conditionally exclude a field based on the result of some computation. In order to support this use case, we will add a new system variable REMOVE. When a field f is set to the value of an expression, and that expression evaluates to $$REMOVE, f is excluded from the resulting document.

Suppose, for example, that you wanted to include the field middleInitial, unless its value was the empty string. This could be achieved as shown below:

> db.names.drop();
> db.names.insert({last: "Smith", middleInitial: "H", first: "John"});
> db.names.insert({last: "Doe", middleInitial: "", first: "Jane"});
 
// Here we have removed the middleInitial field, but only in those documents where it contained the empty string.
> db.names.aggregate([{$project: {
    _id: 0,
    last: 1,
    middleInitial: {$cond: {if: {$eq: ["", "$middleInitial"]}, then: "$$REMOVE", else: "$middleInitial"}},
    first: 1
}}]);
{ "last" : "Smith", "first" : "John", "middleInitial" : "H" }
{ "last" : "Doe", "first" : "Jane" }



 Comments   
Comment by Githook User [ 24/Jul/17 ]

Author:

{u'username': u'kay-kim', u'name': u'kay', u'email': u'kay.kim@10gen.com'}

Message: DOCS-10022: 3.6 REMOVE agg variable
Branch: master
https://github.com/mongodb/docs/commit/0a6130e8dfa26beae5553cbac91c2d7d614e47b1

Comment by Githook User [ 24/Jul/17 ]

Author:

{u'username': u'kay-kim', u'name': u'kay', u'email': u'kay.kim@10gen.com'}

Message: DOCS-10022: 3.6 REMOVE agg variable
Branch: wip-3.6
https://github.com/mongodb/docs/commit/94aad56651762a5879cd9e50b52552ef7fdcdd2c

Generated at Thu Feb 08 07:59:39 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.