-
Notifications
You must be signed in to change notification settings - Fork 3
Ilias_Khugaev-w4-Databases #28
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
base: main
Are you sure you want to change the base?
Ilias_Khugaev-w4-Databases #28
Conversation
| export const uri = 'mongodb+srv://Ilias:zePnKS09BRPZBwaW@cluster0.w5e36f8.mongodb.net/?retryWrites=true&w=majority&appName=Cluster0'; | ||
| const client = new MongoClient(uri); |
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: It is not a good practice to store your URL/keys in the code. Better to have an environment variable file : )
| 'Country': { | ||
| '$regex': '^[A-Z]+$' |
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: interesting way to match continent name and it is correct. However, in the real working situation we tend to avoid using REGEX as it is slow. The performance is important especially when you have a lot of requests per second coming to your backend service.
Continents are fixed and don't have a lot of values, so you can use IN here.
| }, { | ||
| '$match': { | ||
| 'Age': age, | ||
| 'Year': year | ||
| } |
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: Why don't you merge these two $match into one?
| await accounts.updateOne( | ||
| { accountNumber: to }, | ||
| { $inc: { balance: amount } }, | ||
| { session } | ||
| ); | ||
| await accounts.updateOne( | ||
| { accountNumber: to }, | ||
| { $push: { account_changes: transactionsDitals(amount, change_number, remark)} }, | ||
| { session } | ||
| ); |
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: you can merge $inc and $push in one updateOne function.
| export const transactions = async (client, from, to, amount, remark) => { | ||
| const accounts = client.db("databaseWeek4").collection("account"); | ||
| const session = client.startSession(); | ||
| const change_number = uuid4(); |
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 to use UUID here!
| async function run() { | ||
| try { | ||
| // Connect the client to the server (optional starting in v4.7) | ||
| await client.connect(); | ||
| // Send a ping to confirm a successful connection | ||
| await client.db("admin").command({ ping: 1 }); | ||
| console.log("Pinged your deployment. You successfully connected to MongoDB!"); | ||
| } finally { | ||
| // Ensures that the client will close when you finish/error | ||
| await client.close(); | ||
| } | ||
| } | ||
| run().catch(console.dir); |
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.
You can use this file to test connection but in the real working environment, you don't need to upload this file to git.
No description provided.