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