Skip to content

Conversation

@Narpimers
Copy link

No description provided.

@yunchen4 yunchen4 self-assigned this Jun 10, 2025
Comment on lines +4 to +5
export const uri = 'mongodb+srv://Ilias:zePnKS09BRPZBwaW@cluster0.w5e36f8.mongodb.net/?retryWrites=true&w=majority&appName=Cluster0';
const client = new MongoClient(uri);

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 : )

Comment on lines +59 to +60
'Country': {
'$regex': '^[A-Z]+$'

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.

Comment on lines +63 to +67
}, {
'$match': {
'Age': age,
'Year': year
}

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?

Comment on lines +32 to +41
await accounts.updateOne(
{ accountNumber: to },
{ $inc: { balance: amount } },
{ session }
);
await accounts.updateOne(
{ accountNumber: to },
{ $push: { account_changes: transactionsDitals(amount, change_number, remark)} },
{ session }
);

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();

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!

Comment on lines +14 to +26
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);

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants