Database war Mysql & Mongodb Other Queries
English

Hey my friends, a new post about this war. I don't know which is better, but I'll try to figure it out. I hope y'all enjoy this series. Here we go!
This time I'm going to talk about a few queries that can help you!
Count
If you need to count how many registers exist with the same query.
Mysql
SELECT count(*) FROM crews WHERE captain = 'Luffy';
MongoDB
db.crews.find({"captain":"Luffy"}).count()
Sum
If you need to sum a specific field.
Mysql
SELECT SUM(members) FROM crews;
MongoDB
db.crews.aggregate(
{
$match:{}
},
{
$group: {
_id: null,
sum: {
$sum: "$members"
}
}
});
Min
If you need to get the min field of a query.
Mysql
SELECT MIN(members) FROM crews;
MongoDB
db.crews.aggregate(
{
$match:{}
},
{
$group: {
_id: null,
min: {
$min: "$members"
}
}
});
Max
If you need to get the max field of a query.
Mysql
SELECT MAX(members) FROM crews;
MongoDB
db.crews.aggregate(
{
$match:{}
},
{
$group: {
_id: null,
max: {
$max: "$members"
}
}
});
Conclusion
- Structure: Mysql is easier than MongoDB.
Would you like to learn about other things?
I hope you enjoy my post and remember that I am just a Dev like you!
About the author
I am a backend developer (PHP, Javascript, Laravel, Node ) , I know frontend (css, html, react, react-native) but it is not my passion, I have experience as a linux system administrator. I have deployed products in googlecloud, I have experience with integration and maintenance to mobile applications, in addition to working with database sql (mysql, postgresql) and nosql (mongodb)
Comments
Join the discussionNo comments yet. Be the first to comment.





