File tree 3 files changed +85
-1
lines changed
3 files changed +85
-1
lines changed Original file line number Diff line number Diff line change @@ -33,4 +33,4 @@ yarn-error.log*
33
33
34
34
# typescript
35
35
* .tsbuildinfo
36
- next-env.d.ts
36
+ next-env.d.ts
Original file line number Diff line number Diff line change
1
+ import clientPromise from "../lib/mongodb" ;
2
+
3
+ export default function Movies ( { movies } ) {
4
+ return (
5
+ < div >
6
+ < h1 > Top 20 Movies of All Time</ h1 >
7
+ < p >
8
+ < small > (According to Metacritic)</ small >
9
+ </ p >
10
+ < ul >
11
+ { movies . map ( ( movie ) => (
12
+ < li >
13
+ < h2 > { movie . title } </ h2 >
14
+ < h3 > { movie . _id } </ h3 >
15
+ < p > { movie . plot } </ p >
16
+ </ li >
17
+ ) ) }
18
+ </ ul >
19
+ </ div >
20
+ ) ;
21
+ }
22
+
23
+ export async function getServerSideProps ( context ) {
24
+ try {
25
+ const client = await clientPromise ;
26
+
27
+ const db = client . db ( "sample_mflix" ) ;
28
+
29
+ const movies = await db
30
+ . collection ( "movies" )
31
+ . find ( { } )
32
+ . sort ( { metacritic : - 1 } )
33
+ . limit ( 10 )
34
+ . toArray ( ) ;
35
+
36
+ return {
37
+ props : { movies : JSON . parse ( JSON . stringify ( movies ) ) } ,
38
+ } ;
39
+ } catch ( error ) {
40
+ console . log ( error ) ;
41
+ }
42
+ }
Original file line number Diff line number Diff line change
1
+ import clientPromise from "../lib/mongodb" ;
2
+
3
+ export default function Top ( { movies } ) {
4
+ return (
5
+ < div >
6
+ < h1 > Top 1000 Movies of All Time</ h1 >
7
+ < p >
8
+ < small > (According to Metacritic)</ small >
9
+ </ p >
10
+ < ul >
11
+ { movies . map ( ( movie ) => (
12
+ < li >
13
+ < h2 > { movie . title } </ h2 >
14
+ < h3 > { movie . metacritic } </ h3 >
15
+ < p > { movie . plot } </ p >
16
+ </ li >
17
+ ) ) }
18
+ </ ul >
19
+ </ div >
20
+ ) ;
21
+ }
22
+
23
+ export async function getStaticProps ( ) {
24
+ try {
25
+ const client = await clientPromise ;
26
+
27
+ const db = client . db ( "sample_mflix" ) ;
28
+
29
+ const movies = await db
30
+ . collection ( "movies" )
31
+ . find ( { } )
32
+ . sort ( { metacritic : - 1 } )
33
+ . limit ( 1000 )
34
+ . toArray ( ) ;
35
+
36
+ return {
37
+ props : { movies : JSON . parse ( JSON . stringify ( movies ) ) } ,
38
+ } ;
39
+ } catch ( error ) {
40
+ console . log ( error ) ;
41
+ }
42
+ }
You can’t perform that action at this time.
0 commit comments