From 7f6a3e5547abdddc211a6e0a7bba6b6818585862 Mon Sep 17 00:00:00 2001
From: 4koglin <4koglin@informatik.uni-hamburg.de>
Date: Mon, 24 Jul 2017 11:07:06 +0200
Subject: [PATCH] added section 'Aggregation' and text search in 'Queries'
---
mkdocs.yml | 1 +
src/index.md | 5 ++
src/topics/aggregation/index.md | 49 +++++++++++
src/topics/queries/index.md | 145 +++++++++++++++++++++++---------
4 files changed, 160 insertions(+), 40 deletions(-)
create mode 100644 src/topics/aggregation/index.md
diff --git a/mkdocs.yml b/mkdocs.yml
index 19938a6..dc37ff7 100644
--- a/mkdocs.yml
+++ b/mkdocs.yml
@@ -12,6 +12,7 @@ pages:
- 'CRUD': 'topics/crud/index.md'
- 'Schema and Types': 'topics/schema/index.md'
- 'Queries': 'topics/queries/index.md'
+ - 'Aggregation': 'topics/aggregation/index.md'
- 'Real-Time Queries': 'topics/realtime/index.md'
- 'User Management': 'topics/user-management/index.md'
- 'Baqend Code': 'topics/baqend-code/index.md'
diff --git a/src/index.md b/src/index.md
index 639b6d3..a36651d 100644
--- a/src/index.md
+++ b/src/index.md
@@ -48,6 +48,11 @@ Learn how to use Baqend to develop your app.
Queries
Retrieve specific data
from Baqend by
performing queries.
+
+
+ Aggregation
+ Analyze, transform or
process your data.
+
Real-Time Queries
diff --git a/src/topics/aggregation/index.md b/src/topics/aggregation/index.md
new file mode 100644
index 0000000..a482493
--- /dev/null
+++ b/src/topics/aggregation/index.md
@@ -0,0 +1,49 @@
+# Aggregation
+
+With aggregation you can perform a variety of operations on your data, e.g. group values from multiple documents together or transform your data and compute new values.
+
+The Baqend SDK is using the [MongoDB Aggregation Framework](https://docs.mongodb.com/manual/core/aggregation-pipeline/) for data aggregation. This Framkework is modeled on the concept of a pipeline, which consists of multiple stages that process and transform your data and pass it to the next stage successively.
+
+## Stages
+Each stage performs an operation on the input data. After processing the operation, the result serves as input for the next stage.
+ For all possible stage operations see the [MongoDB Aggregation Pipeline Operators](https://docs.mongodb.com/manual/reference/operator/aggregation/).
+
+The Baqend SDK feature an aggregation builder (similar to the [Query Builder](../queries)).
+
+An aggregation stage is added via the `addstage` method.
+```js
+DB.Todo.aggregate().addStage({
+ $match : { "activities.start": { "$lte": { "$date": new Date().toISOString() } }
+}).addStage({
+ $group : { _id: $done, count: { $sum: 1} }
+}).result((result) => {
+ console.log(count);
+});
+```
+The above aggregation first filters all todos, which contain an activity in its activities list that has been started before the current date, and then group and count them by their "done" state.
+
+
+
+
DB.GeoPoint.current(). This only works with an HTTPS connection.
References can and should be used in filters. Internally references are converted to ids
- and used for filtering. To get all Todos owned by the currently logged-in user, we can simply use the User instance
+ and used for filtering. To get all Todos owned by the currently logged-in user, we can simply use the User instance
in the query builder:
```js
@@ -274,7 +274,7 @@ login process see the User, Roles and Perm
## Sorting
-It is possible to sort the query result for one or more attributes. The query builder can be used to specify
+It is possible to sort the query result for one or more attributes. The query builder can be used to specify
which attributes shall be used for sorting. Let's sort our query result by name:
```js
DB.Todo.find()
@@ -283,8 +283,8 @@ DB.Todo.find()
.resultList(...)
```
-If you use more than one sort criterion, the order of the result reflects the order in which the sort methods were
-called. The following query will list all active tasks before the inactive ones and sort the tasks by their name in
+If you use more than one sort criterion, the order of the result reflects the order in which the sort methods were
+called. The following query will list all active tasks before the inactive ones and sort the tasks by their name in
ascending order.
```js
DB.Todo.find()
@@ -294,10 +294,10 @@ DB.Todo.find()
.resultList(...)
```
-When calling `descending('active')` before `ascending('name')` the result is sorted by name and
-then by active flag, which is only relevant for multiple todos having the same name.
+When calling `descending('active')` before `ascending('name')` the result is sorted by name and
+then by active flag, which is only relevant for multiple todos having the same name.
-You can also set the sort criteria with the MongoDB [orderby](http://docs.mongodb.org/manual/reference/operator/meta/orderby/)
+You can also set the sort criteria with the MongoDB [orderby](http://docs.mongodb.org/manual/reference/operator/meta/orderby/)
syntax by using the `sort()` method. An equivalent expression to the above is this:
```js
DB.Todo.find()
@@ -307,7 +307,7 @@ DB.Todo.find()
```
## Offset and Limit
-On larger data sets you usually don't want to load everything at once. Its often reasonable to instead page through the
+On larger data sets you usually don't want to load everything at once. Its often reasonable to instead page through the
query results. It is therefore possible to skip objects and limit the result size.
```js
var page = 3;
@@ -322,9 +322,9 @@ DB.Todo.find()
```
text filter, sorts the results always by relevance. Adding an additional sort criteria has no effect on the ordering.