New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: update Getting-Started.md #3213
Conversation
docs/Getting-Started.md
Outdated
@@ -176,15 +176,15 @@ async function routes (fastify, options) { | |||
|
|||
fastify.get('/animals', async (request, reply) => { | |||
const result = await collection.find().toArray() | |||
if (result.length === 0) { | |||
if (result?.length) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fastify supports node.js 10 and 12 that does not support this syntax by default so it would be better to keep the old check
Would you mind targeting the next
branch instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your feedback. Could I mantain "main" branch replacing
if(result?.length) with if(!result || result && !result.length) ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
collection.find().toArray()
must return Array
even if no document exist. I think it do not need any change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good, thank you. I rolled back this line.
Oops, it cause by the recent update of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
With current example from Getting-started.md, I get this error and server doesn't resolve anything.
"name":"FastifyError"
"code":"FST_ERR_PROMISE_NOT_FULFILLED","statusCode":500}
"msg":"Promise may not be fulfilled with 'undefined' when statusCode is not 204"
Because "result" return undefined with an empty dataset and check only for null values doesn't avoid the exception.