AGGREGATE Movie tutorial: Difference between revisions
From NoSQLZoo
Created page with "==Alien== <div class=q data-lang="mongo"> Use aggregate to show details of the movie "Alien" <pre class=def> db.movie.aggregate([ {$match:{ title:"Alien" }} ])..." |
|||
| (2 intermediate revisions by the same user not shown) | |||
| Line 3: | Line 3: | ||
Use aggregate to show details of the movie "Alien" | Use aggregate to show details of the movie "Alien" | ||
<pre class=def> | <pre class=def> | ||
db. | db.movies.aggregate([ | ||
{$match:{ | {$match:{ | ||
title:"Alien" | title:"Alien" | ||
| Line 15: | Line 15: | ||
}} | }} | ||
]) | ]) | ||
</div> | |||
</div> | |||
==John Hurt in Harry Potter== | |||
<div class=q data-lang="mongo"> | |||
List the Harry Potter movies that feature John Hurt. | |||
<pre class=def> | |||
</pre> | |||
<div class=ans> | |||
db.movies.aggregate([ | |||
{$match:{ | |||
cast:"John Hurt" | |||
}}, | |||
{$match:{title:{$regex:'Harry Potter'}}}, | |||
{$project:{title:1,_id:0}} | |||
]).pretty() | |||
</div> | </div> | ||
</div> | </div> | ||
Latest revision as of 22:16, 11 May 2017
Alien
Use aggregate to show details of the movie "Alien"
db.movies.aggregate([
{$match:{
title:"Alien"
}}
])
db.movie.aggregate([
{$match:{
title:"Alien"
}}
])
John Hurt in Harry Potter
List the Harry Potter movies that feature John Hurt.
db.movies.aggregate([
{$match:{
cast:"John Hurt"
}},
{$match:{title:{$regex:'Harry Potter'}}},
{$project:{title:1,_id:0}}
]).pretty()