File tree Expand file tree Collapse file tree 3 files changed +36
-17
lines changed Expand file tree Collapse file tree 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 }) {
1111 { movies . map ( ( movie ) => (
1212 < li >
1313 < h2 > { movie . title } </ h2 >
14- < h3 > { movie . _id } </ h3 >
14+ < h3 > { movie . metacritic } </ h3 >
1515 < p > { movie . plot } </ p >
1616 </ li >
1717 ) ) }
@@ -37,6 +37,6 @@ export async function getServerSideProps(context) {
3737 props : { movies : JSON . parse ( JSON . stringify ( movies ) ) } ,
3838 } ;
3939 } catch ( e ) {
40- console . log ( e ) ;
40+ console . error ( e ) ;
4141 }
4242}
Original file line number Diff line number Diff line change @@ -21,22 +21,22 @@ export default function Top({ movies }) {
2121}
2222
2323export async function getStaticProps ( ) {
24- try {
25- const client = await clientPromise ;
24+ try {
25+ const client = await clientPromise ;
2626
27- const db = client . db ( "sample_mflix" ) ;
27+ const db = client . db ( "sample_mflix" ) ;
2828
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 ( ) ;
3535
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+ }
4242}
You can’t perform that action at this time.
0 commit comments