project static method

Map<String, Object> project(
  1. Map<String, Object> fields
)

Constructs a MongoDB $project aggregation stage.

The $project stage passes along the documents with the requested fields to the next stage in the pipeline. The specified fields can be existing fields from the input documents or newly computed fields.

fields Map of field specifications where values can be:

  • 1 or true: Include the field
  • 0 or false: Exclude the field
  • Expression: Computed field value

Example:

var query = DQ.project({
  'name': 1,
  'age': 1,
  '_id': 0,
  'fullName': {'\$concat': ['\$firstName', ' ', '\$lastName']}
});

Implementation

static Map<String, Object> project(Map<String, Object> fields) {
  return {
    '\$project': {
      ...fields,
    }
  };
}