Professional Documents
Culture Documents
Queries PDF
Queries PDF
Queries
Task 1
for(elem in doc){
if (elem == "info"){
for(child in doc[elem]){
let s = doc[elem][child]+'';
if(s.includes("Opera") ){
print(doc["person-name"]);
break; //if a field contains 2 “opera” to print it only once.
}
}
}
}
}
);
Daniela Pistol
f) For each movie person whose birth place is known, the latitude, longitude
and population of that city (if that information exists in the city document)
▪ Query:
db.movies.aggregate([
{
$unwind: "$info.birthnotes"
},
{ $project : { birthplace : { $split: ["$info.birthnotes", ", "] }, _id:0 , "person-
name":1}},
{ $project:
{ city : { $arrayElemAt : [ "$birthplace", 0 ]}, "person-name":1 }
},
{
$lookup:{
from: "cities",
localField: "city",
foreignField: "name",
as: "infocity"
}
},
{
$project:{
"person-name":1,
"city":1,
"infocity.population":1,
"infocity.location":1
}
}
]);