Commit c812b90d authored by Marcel Huber's avatar Marcel Huber
Browse files

updated manual join solutions of MongoDBIntro

parent dea3fc59
......@@ -770,20 +770,6 @@ db.employees.findOne({_id: db.employees.find({name:"Moneo"})[0].manager})
----
=====
endif::exercise_solution[]
ifdef::blubby[]
. Finden Sie die Kinder von *Chani*.
// aus einer früheren Aufgabe?!
ifdef::exercise_solution[]
+
[example,title=""]
=====
.Kinder von *Chani*
[source, javascript]
----
db.employees.find({'family.mother': "Chani"})
=====
endif::exercise_solution[]
endif::blubby[]
[id='mongodb-joins-graphlookup']
==== Aufgabe {ex_number}{counter:subtopic}: Joins mit `$graphLookup` Operator
......@@ -844,22 +830,21 @@ endif::exercise_solution[]
Finden Sie eine Möglichkeit einen Join mittels https://docs.mongodb.com/manual/reference/operator/aggregation/lookup/[`$lookup`] Operator durchzuführen?
.[#lookup-manager-moneo-which-data]#Q{counter:query_number} Passendes DataSet#
Welche Daten passen besser zur `$lookup` Abfrage, die von <<mongodb-joins-manual>> oder von <<mongodb-joins-graphlookup>>?
Welche Daten passen besser zu einer einfachen `$lookup` Abfrage, die von <<mongodb-joins-manual>> oder von <<mongodb-joins-graphlookup>>?
ifndef::exercise_solution[]
[example,title=""]
=====
{nbsp}
{nbsp}
{nbsp}
=====
endif::exercise_solution[]
ifdef::exercise_solution[]
[example,title=""]
=====
Die Daten der Aufgabe <<mongodb-joins-graphlookup>> passen gut für diese einfache Join Abfrage.
Die Daten der Aufgabe <<mongodb-joins-graphlookup>> passen gut für diese einfache Join Abfrage über verschiedene Collections.
=====
endif::exercise_solution[]
.[#lookup-manager-moneo]#Q{counter:query_number} Manager von *Moneo* ermitteln#
Erstellen Sie eine Abfrage um den Manager von *Moneo* anzuzeigen unter Verwendung von `localField` und `foreignField`.
......@@ -873,7 +858,10 @@ Erstellen Sie eine Abfrage um den Manager von *Moneo* anzuzeigen unter Verwendun
{_id: ObjectId("4d85c7039ab0fd70a117d733"), name: "Siona", manager: ["Leto", "Moneo"] }
----
[example,title=""]
=====
.Manager von *Moneo* mit einfachem `$lookup` Aggregat
ifdef::exercise_solution[]
[source,javascript]
----
db.employees.aggregate({
......@@ -898,16 +886,35 @@ db.employees.aggregate({
}
})
----
endif::exercise_solution[]
ifndef::exercise_solution[]
{nbsp}
{nbsp}
{nbsp}
{nbsp}
endif::exercise_solution[]
.Resultat der Abfrage
ifdef::exercise_solution[]
[source, javascript]
----
{ "name" : "Moneo", "managers" : [ { "name" : "Leto" } ] }
----
endif::exercise_solution[]
ifndef::exercise_solution[]
{nbsp}
.[#lookup-manager-moneo]#Q{counter:query_number} Manager von *Moneo*#
{nbsp}
endif::exercise_solution[]
=====
.[#lookup-manager-moneo]#Q{counter:query_number} Manager von *Moneo* über verschiedene Collections ermitteln#
Erstellen Sie eine Abfrage um den Manager von *Moneo* anzuzeigen wenn die Daten in zwei unterschiedlichen Collections abgelegt sind.
.Daten
.Daten der beiden Collections
[source,javascript]
----
db.employees.insertMany([
......@@ -920,52 +927,62 @@ db.managers.insertMany([
{_id: ObjectId("4d85c7039ab0fd70a117d741"), name: "Moneo", department: "Research"}
])
----
ifndef::exercise_solution[]
[example,title=""]
=====
{nbsp}
{nbsp}
{nbsp}
=====
endif::exercise_solution[]
ifdef::exercise_solution[]
[example,title=""]
=====
.Manager von *Moneo* mit `$lookup`
ifdef::exercise_solution[]
[source, javascript]
----
db.employees.aggregate({
$lookup: {
from: "managers",
localField: "manager",
foreignField: "name",
as: "managers"
}
$lookup: {
from: "managers",
localField: "manager",
foreignField: "name",
as: "managers"
}
}, {
$match: {
"name": "Moneo"
}
$match: {
"name": "Moneo"
}
}, {
$project: {
_id: 0,
manager: 0,
managers: {
_id: 0
}
$project: {
_id: 0,
manager: 0,
managers: {
_id: 0
}
}
})
----
endif::exercise_solution[]
ifndef::exercise_solution[]
{nbsp}
{nbsp}
{nbsp}
{nbsp}
endif::exercise_solution[]
.Resultat der Abfrage
ifdef::exercise_solution[]
[source, javascript]
----
{ "name" : "Duncan", "managers" : [ { "name" : "Leto", "department" : "Sales" } ] }
{ "name" : "Moneo", "managers" : [ { "name" : "Leto", "department" : "Sales" } ] }
{ "name" : "Siona", "managers" : [ { "name" : "Leto", "department" : "Sales" }, { "name" : "Moneo", "department" : "Research" } ] }
----
=====
endif::exercise_solution[]
ifndef::exercise_solution[]
{nbsp}
{nbsp}
{nbsp}
endif::exercise_solution[]
=====
include::{exercises_dir}MongodbShardingScalingOut.asc[]
......
......@@ -770,20 +770,6 @@ db.employees.findOne({_id: db.employees.find({name:"Moneo"})[0].manager})
----
=====
endif::exercise_solution[]
ifdef::blubby[]
. Finden Sie die Kinder von *Chani*.
// aus einer früheren Aufgabe?!
ifdef::exercise_solution[]
+
[example,title=""]
=====
.Kinder von *Chani*
[source, javascript]
----
db.employees.find({'family.mother': "Chani"})
=====
endif::exercise_solution[]
endif::blubby[]
[id='mongodb-joins-graphlookup']
==== Aufgabe {ex_number}{counter:subtopic}: Joins mit `$graphLookup` Operator
......@@ -844,22 +830,21 @@ endif::exercise_solution[]
Finden Sie eine Möglichkeit einen Join mittels https://docs.mongodb.com/manual/reference/operator/aggregation/lookup/[`$lookup`] Operator durchzuführen?
.[#lookup-manager-moneo-which-data]#Q{counter:query_number} Passendes DataSet#
Welche Daten passen besser zur `$lookup` Abfrage, die von <<mongodb-joins-manual>> oder von <<mongodb-joins-graphlookup>>?
Welche Daten passen besser zu einer einfachen `$lookup` Abfrage, die von <<mongodb-joins-manual>> oder von <<mongodb-joins-graphlookup>>?
ifndef::exercise_solution[]
[example,title=""]
=====
{nbsp}
{nbsp}
{nbsp}
=====
endif::exercise_solution[]
ifdef::exercise_solution[]
[example,title=""]
=====
Die Daten der Aufgabe <<mongodb-joins-graphlookup>> passen gut für diese einfache Join Abfrage.
Die Daten der Aufgabe <<mongodb-joins-graphlookup>> passen gut für diese einfache Join Abfrage über verschiedene Collections.
=====
endif::exercise_solution[]
.[#lookup-manager-moneo]#Q{counter:query_number} Manager von *Moneo* ermitteln#
Erstellen Sie eine Abfrage um den Manager von *Moneo* anzuzeigen unter Verwendung von `localField` und `foreignField`.
......@@ -873,7 +858,10 @@ Erstellen Sie eine Abfrage um den Manager von *Moneo* anzuzeigen unter Verwendun
{_id: ObjectId("4d85c7039ab0fd70a117d733"), name: "Siona", manager: ["Leto", "Moneo"] }
----
[example,title=""]
=====
.Manager von *Moneo* mit einfachem `$lookup` Aggregat
ifdef::exercise_solution[]
[source,javascript]
----
db.employees.aggregate({
......@@ -898,16 +886,35 @@ db.employees.aggregate({
}
})
----
endif::exercise_solution[]
ifndef::exercise_solution[]
{nbsp}
{nbsp}
{nbsp}
{nbsp}
endif::exercise_solution[]
.Resultat der Abfrage
ifdef::exercise_solution[]
[source, javascript]
----
{ "name" : "Moneo", "managers" : [ { "name" : "Leto" } ] }
----
endif::exercise_solution[]
ifndef::exercise_solution[]
{nbsp}
.[#lookup-manager-moneo]#Q{counter:query_number} Manager von *Moneo*#
{nbsp}
endif::exercise_solution[]
=====
.[#lookup-manager-moneo]#Q{counter:query_number} Manager von *Moneo* über verschiedene Collections ermitteln#
Erstellen Sie eine Abfrage um den Manager von *Moneo* anzuzeigen wenn die Daten in zwei unterschiedlichen Collections abgelegt sind.
.Daten
.Daten der beiden Collections
[source,javascript]
----
db.employees.insertMany([
......@@ -920,52 +927,62 @@ db.managers.insertMany([
{_id: ObjectId("4d85c7039ab0fd70a117d741"), name: "Moneo", department: "Research"}
])
----
ifndef::exercise_solution[]
[example,title=""]
=====
{nbsp}
{nbsp}
{nbsp}
=====
endif::exercise_solution[]
ifdef::exercise_solution[]
[example,title=""]
=====
.Manager von *Moneo* mit `$lookup`
ifdef::exercise_solution[]
[source, javascript]
----
db.employees.aggregate({
$lookup: {
from: "managers",
localField: "manager",
foreignField: "name",
as: "managers"
}
$lookup: {
from: "managers",
localField: "manager",
foreignField: "name",
as: "managers"
}
}, {
$match: {
"name": "Moneo"
}
$match: {
"name": "Moneo"
}
}, {
$project: {
_id: 0,
manager: 0,
managers: {
_id: 0
}
$project: {
_id: 0,
manager: 0,
managers: {
_id: 0
}
}
})
----
endif::exercise_solution[]
ifndef::exercise_solution[]
{nbsp}
{nbsp}
{nbsp}
{nbsp}
endif::exercise_solution[]
.Resultat der Abfrage
ifdef::exercise_solution[]
[source, javascript]
----
{ "name" : "Duncan", "managers" : [ { "name" : "Leto", "department" : "Sales" } ] }
{ "name" : "Moneo", "managers" : [ { "name" : "Leto", "department" : "Sales" } ] }
{ "name" : "Siona", "managers" : [ { "name" : "Leto", "department" : "Sales" }, { "name" : "Moneo", "department" : "Research" } ] }
----
=====
endif::exercise_solution[]
ifndef::exercise_solution[]
{nbsp}
{nbsp}
{nbsp}
endif::exercise_solution[]
=====
include::{exercises_dir}MongodbShardingScalingOut.asc[]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment