-
Notifications
You must be signed in to change notification settings - Fork 10
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
assignment week4 Fatemeh Alinejad #51
base: main
Are you sure you want to change the base?
Conversation
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.
Hi Fatemeh,
Good job! I will approve it.
I left some comments related to real working situation. If you have any questions don't hesitate to contact me on slack.
Have a nice weekend!
const db = client.db("databaseWeek4"); | ||
const collection = db.collection("ex1-aggregation"); |
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.
suggestion: since these two strings are used across the files, it's better to make them constants.
const db = client.db("databaseWeek4"); | ||
const collection = db.collection("ex1-aggregation"); |
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.
Same constant suggestion applies here too.
const db = client.db("databaseWeek4"); | ||
const collection = db.collection("accounts"); |
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.
Same constant suggestion applies here too.
if (from.balance < amount) { | ||
throw new Error("Insufficient balance"); | ||
} |
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.
Early returns and throwing are always good if applicable :)
const changeNumberFrom = from.account_changes.length + 1; | ||
const changeNumberTo = to.account_changes.length + 1; |
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.
suggestion: using fromAccount.account_changes.length + 1
to know the next change_number
is OK.
However, in real life one account may have a lot more change records. We don't really care what those changes are, we just want to know the maximum change number. Fetching all changes with the account can be expensive (since you need to transfer more bytes in the network. When you download something big from Internet, it is always slower than dowloading smaller files using the same network), and we try to only fetch the columns we need.
One solution is to have a function to get only the maximum change number (you have learned MAX
sql syntax), and when you fetch the account data you don't fetch the changes column.
No description provided.