#Querying databases
1 messages · Page 1 of 1 (latest)
I don't know about getStaticProps, but it's definitely possible to query a database from getServerSideProps. We do it in this example:
https://github.com/chiselstrike/chiselstrike-examples/blob/34de7160c49fa42eb49290f6e7ed8663f6e4fee7/nextjs/pages/profile.js#L7
Maybe you should try first with getServerSideProps, to narrow it down. If that works but getStaticProps doesn't, then it's likely that getStaticProps gets invoked at a different time than you expect. Its documentation says it's for build time, not load time.
OTOH, it can also run in the background, it seems...
https://nextjs.org/docs/basic-features/data-fetching/get-static-props#when-does-getstaticprops-run
I guess... I could try getServerSideProps... not exactly what I wanted, but OK if it works...
My friend... could you explain what is this? where does it come from? "@chiselstrike/api"
Oh, that's just a different database. Doesn't apply to you if you use MongoDB.