i try to research about MongoDB, today i use MySQL 5.5.
i have a SaaS services and need one database there can handle a lost of data, rows and more, and its need to be fast.
What i can read is MongoDB is DB in the servers memery if its true, what happen if server go down?
in MySQL all its storge on the harddrive, but the database can handle more then server allow, else you need somthink like cluster database and autoload balance.
What i have read the MongoDB its easy to setup to run on more computers, but is that true?
I hobe on somthink h开发者_StackOverflowelp here, maby its not MySQL or MongoDB i need, maby its a 3 database setup?
MongoDB is a non-relational database. no joins, no rows, no columns. It's Document based. MySQL is a relation database.
For example: We have some servers. Each server has a name, ip, admins, and OS. But some servers have extra data 'master'. If is_slave == true: print name of the master server.
In MongoDB (without index; it's not relevant here):
{
"_id": ObjectId("4da5609a7650bf3f57000000"),
"name": "Testarossa",
"ip": "0.0.0.0",
"admins": [
{ "username": "yitsushi", "has_sudo": true },
{ "username": "lokko", "has_sudo": false }
],
"os_name": "Gentoo",
"is_slave": false
},
{
"_id": ObjectId("4decc3d1f2d26f6716000001"),
"name": "Amanuat",
"ip": "0.0.0.1",
"admins": [
{ "username": "yitsushi", "has_sudo": false },
{ "username": "parandokht", "has_sudo": true }
],
"os_name": "Ubuntu 10.10",
"is_slave": true,
"master": {
"name": "Testarossa",
"server": {
"$ref": "servers",
"$id": ObjectId("4da5609a7650bf3f57000000");
}
}
}
You can see the master field is not required, so you don't need to define it in each document instead of null
/0
values. And you can define an Array (admins) instead of related tables. In master field: we define an object with two properties: name (for print name of the server) and a reference (we can create a link with doc['master']['server']['$id']
or we can fetch with an other query the full document of the master server).
In MySQL we need a servers, an admins and a server_admins table (least) and some unnecessary fields whose value is null
.
MongoDB and MySQL is not same category. MongoDB is a non-relational, MySQL is a relational database. Completely different logic and attitude need to MongoDB or MySQL.
A perfect compare grid: MongoDB, CouchDB, MySQL Compare Grid at www.mongodb.org
MongoDB tries to hold as much as possible in memory. However all data is written to harddisk too.
MongoDB concentrate on Speed so when the server crashes the risk is a bit higher that you loose maybe the last few entries.
So when data safety is your first goal take something else. When you need speed and a comfortable database MongoDB is a good choice.
精彩评论