Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions _includes/js/queries.md
Original file line number Diff line number Diff line change
Expand Up @@ -444,26 +444,24 @@ The following example is a pipeline similar to `distinct` grouping by name field

```javascript
const pipelineObject = {
group: { objectId: '$name' }
$group: { _id: '$name' }
};

const pipelineArray = [
{ group: { objectId: '$name' } }
{ $group: { _id: '$name' } }
];
```

For a list of available operators please refer to [Mongo Aggregate Documentation](https://docs.mongodb.com/v3.2/reference/operator/aggregation/).

* Note: Most operations in Mongo Aggregate Documentation will work with Parse Server, but `_id` doesn't exist. Please replace with `objectId`.

Group pipeline is similar to `distinct`.

You can group by a field.

```javascript
// score is the field. $ before score lets the database know this is a field
const pipeline = [
{ group: { objectId: '$score' } }
{ $group: { _id: '$score' } }
];
const query = new Parse.Query("User");
query.aggregate(pipeline)
Expand All @@ -480,7 +478,7 @@ You can apply collective calculations like $sum, $avg, $max, $min.
```javascript
// total will be a newly created field to hold the sum of score field
const pipeline = [
{ group: { objectId: null, total: { $sum: '$score' } } }
{ $group: { _id: null, total: { $sum: '$score' } } }
];
const query = new Parse.Query("User");
query.aggregate(pipeline)
Expand All @@ -496,7 +494,7 @@ Project pipeline is similar to `keys` or `select`, add or remove existing fields

```javascript
const pipeline = [
{ project: { name: 1 } }
{ $project: { name: 1 } }
];
const query = new Parse.Query("User");
query.aggregate(pipeline)
Expand All @@ -512,7 +510,7 @@ Match pipeline is similar to `equalTo`.

```javascript
const pipeline = [
{ match: { name: 'BBQ' } }
{ $match: { name: 'BBQ' } }
];
const query = new Parse.Query("User");
query.aggregate(pipeline)
Expand All @@ -528,7 +526,7 @@ You can match by comparison.

```javascript
const pipeline = [
{ match: { score: { $gt: 15 } } }
{ $match: { score: { $gt: 15 } } }
];
const query = new Parse.Query("User");
query.aggregate(pipeline)
Expand Down