Skip to content

Commit ee58e58

Browse files
committed
refactor(Queries): update Aggregate section to use and
1 parent 710d728 commit ee58e58

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

_includes/js/queries.md

+7-9
Original file line numberDiff line numberDiff line change
@@ -444,26 +444,24 @@ The following example is a pipeline similar to `distinct` grouping by name field
444444

445445
```javascript
446446
const pipelineObject = {
447-
group: { objectId: '$name' }
447+
$group: { _id: '$name' }
448448
};
449449

450450
const pipelineArray = [
451-
{ group: { objectId: '$name' } }
451+
{ $group: { _id: '$name' } }
452452
];
453453
```
454454

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

457-
* Note: Most operations in Mongo Aggregate Documentation will work with Parse Server, but `_id` doesn't exist. Please replace with `objectId`.
458-
459457
Group pipeline is similar to `distinct`.
460458

461459
You can group by a field.
462460

463461
```javascript
464462
// score is the field. $ before score lets the database know this is a field
465463
const pipeline = [
466-
{ group: { objectId: '$score' } }
464+
{ $group: { _id: '$score' } }
467465
];
468466
const query = new Parse.Query("User");
469467
query.aggregate(pipeline)
@@ -480,7 +478,7 @@ You can apply collective calculations like $sum, $avg, $max, $min.
480478
```javascript
481479
// total will be a newly created field to hold the sum of score field
482480
const pipeline = [
483-
{ group: { objectId: null, total: { $sum: '$score' } } }
481+
{ $group: { _id: null, total: { $sum: '$score' } } }
484482
];
485483
const query = new Parse.Query("User");
486484
query.aggregate(pipeline)
@@ -496,7 +494,7 @@ Project pipeline is similar to `keys` or `select`, add or remove existing fields
496494

497495
```javascript
498496
const pipeline = [
499-
{ project: { name: 1 } }
497+
{ $project: { name: 1 } }
500498
];
501499
const query = new Parse.Query("User");
502500
query.aggregate(pipeline)
@@ -512,7 +510,7 @@ Match pipeline is similar to `equalTo`.
512510

513511
```javascript
514512
const pipeline = [
515-
{ match: { name: 'BBQ' } }
513+
{ $match: { name: 'BBQ' } }
516514
];
517515
const query = new Parse.Query("User");
518516
query.aggregate(pipeline)
@@ -528,7 +526,7 @@ You can match by comparison.
528526

529527
```javascript
530528
const pipeline = [
531-
{ match: { score: { $gt: 15 } } }
529+
{ $match: { score: { $gt: 15 } } }
532530
];
533531
const query = new Parse.Query("User");
534532
query.aggregate(pipeline)

assets/js/bundle.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)