{"id":162833,"date":"2024-11-04T18:24:18","date_gmt":"2024-11-04T10:24:18","guid":{"rendered":"https:\/\/server.hk\/cnblog\/162833\/"},"modified":"2024-11-04T18:24:19","modified_gmt":"2024-11-04T10:24:19","slug":"%e6%95%99%e4%bd%a0%e5%a6%82%e4%bd%95%e5%88%a9%e7%94%a8mysql%e5%ad%b8%e7%bf%92mongodb%e4%b9%8bsql%e8%aa%9e%e6%b3%95","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/162833\/","title":{"rendered":"\u6559\u4f60\u5982\u4f55\u5229\u7528MySQL\u5b78\u7fd2MongoDB\u4e4bSQL\u8a9e\u6cd5"},"content":{"rendered":"<h1 id=\"%e6%95%99%e4%bd%a0%e5%a6%82%e4%bd%95%e5%88%a9%e7%94%a8mysql%e5%ad%b8%e7%bf%92mongodb%e4%b9%8bsql%e8%aa%9e%e6%b3%95-flLVzWbJaa\">\u6559\u4f60\u5982\u4f55\u5229\u7528MySQL\u5b78\u7fd2MongoDB\u4e4bSQL\u8a9e\u6cd5<\/h1>\n<p>\u5728\u7576\u4eca\u7684\u6578\u64da\u7ba1\u7406\u4e16\u754c\u4e2d\uff0cMySQL\u548cMongoDB\u662f\u5169\u7a2e\u975e\u5e38\u6d41\u884c\u7684\u6578\u64da\u5eab\u7cfb\u7d71\u3002MySQL\u662f\u4e00\u7a2e\u95dc\u4fc2\u578b\u6578\u64da\u5eab\uff0c\u800cMongoDB\u5247\u662f\u4e00\u7a2e\u975e\u95dc\u4fc2\u578b\u6578\u64da\u5eab\u3002\u96d6\u7136\u5b83\u5011\u7684\u67b6\u69cb\u548c\u6578\u64da\u8655\u7406\u65b9\u5f0f\u6709\u6240\u4e0d\u540c\uff0c\u4f46\u5982\u679c\u4f60\u5df2\u7d93\u719f\u6089MySQL\u7684SQL\u8a9e\u6cd5\uff0c\u5b78\u7fd2MongoDB\u7684\u67e5\u8a62\u8a9e\u6cd5\u5c07\u6703\u8b8a\u5f97\u76f8\u5c0d\u5bb9\u6613\u3002\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u5229\u7528MySQL\u7684\u77e5\u8b58\u4f86\u5b78\u7fd2MongoDB\u7684\u67e5\u8a62\u8a9e\u6cd5\u3002<\/p>\n<h2 id=\"mysql%e8%88%87mongodb%e7%9a%84%e5%9f%ba%e6%9c%ac%e6%a6%82%e5%bf%b5-flLVzWbJaa\">MySQL\u8207MongoDB\u7684\u57fa\u672c\u6982\u5ff5<\/h2>\n<p>\u5728\u6df1\u5165\u5b78\u7fd2\u4e4b\u524d\uff0c\u9996\u5148\u4e86\u89e3MySQL\u548cMongoDB\u7684\u57fa\u672c\u6982\u5ff5\u662f\u975e\u5e38\u91cd\u8981\u7684\u3002<\/p>\n<ul>\n<li><strong>MySQL\uff1a<\/strong>\u4e00\u7a2e\u57fa\u65bc\u8868\u683c\u7684\u95dc\u4fc2\u578b\u6578\u64da\u5eab\uff0c\u4f7f\u7528SQL\uff08\u7d50\u69cb\u5316\u67e5\u8a62\u8a9e\u8a00\uff09\u4f86\u9032\u884c\u6578\u64da\u64cd\u4f5c\u3002<\/li>\n<li><strong>MongoDB\uff1a<\/strong>\u4e00\u7a2e\u57fa\u65bc\u6587\u6a94\u7684\u975e\u95dc\u4fc2\u578b\u6578\u64da\u5eab\uff0c\u4f7f\u7528BSON\uff08\u985e\u4f3cJSON\u7684\u683c\u5f0f\uff09\u4f86\u5b58\u5132\u6578\u64da\uff0c\u4e26\u4f7f\u7528MongoDB\u67e5\u8a62\u8a9e\u8a00\u9032\u884c\u64cd\u4f5c\u3002<\/li>\n<\/ul>\n<h2 id=\"%e6%95%b8%e6%93%9a%e7%b5%90%e6%a7%8b%e7%9a%84%e5%b7%ae%e7%95%b0-flLVzWbJaa\">\u6578\u64da\u7d50\u69cb\u7684\u5dee\u7570<\/h2>\n<p>\u5728MySQL\u4e2d\uff0c\u6578\u64da\u4ee5\u8868\u683c\u7684\u5f62\u5f0f\u5b58\u5132\uff0c\u6bcf\u500b\u8868\u7531\u884c\u548c\u5217\u7d44\u6210\u3002\u800c\u5728MongoDB\u4e2d\uff0c\u6578\u64da\u4ee5\u6587\u6a94\u7684\u5f62\u5f0f\u5b58\u5132\uff0c\u6bcf\u500b\u6587\u6a94\u53ef\u4ee5\u6709\u4e0d\u540c\u7684\u7d50\u69cb\uff0c\u9019\u4f7f\u5f97MongoDB\u5728\u8655\u7406\u975e\u7d50\u69cb\u5316\u6578\u64da\u6642\u66f4\u52a0\u9748\u6d3b\u3002<\/p>\n<h3 id=\"mysql%e7%9a%84%e8%a1%a8%e6%a0%bc%e7%b5%90%e6%a7%8b%e7%a4%ba%e4%be%8b-flLVzWbJaa\">MySQL\u7684\u8868\u683c\u7d50\u69cb\u793a\u4f8b<\/h3>\n<pre><code>\nCREATE TABLE users (\n    id INT AUTO_INCREMENT PRIMARY KEY,\n    name VARCHAR(100),\n    email VARCHAR(100)\n);\n<\/code><\/pre>\n<h3 id=\"mongodb%e7%9a%84%e6%96%87%e6%aa%94%e7%b5%90%e6%a7%8b%e7%a4%ba%e4%be%8b-flLVzWbJaa\">MongoDB\u7684\u6587\u6a94\u7d50\u69cb\u793a\u4f8b<\/h3>\n<pre><code>\n{\n    \"_id\": ObjectId(\"60d5f484f1a2c8b1f8e4e1a1\"),\n    \"name\": \"John Doe\",\n    \"email\": \"john@example.com\"\n}\n<\/code><\/pre>\n<h2 id=\"%e6%9f%a5%e8%a9%a2%e8%aa%9e%e6%b3%95%e7%9a%84%e5%b0%8d%e6%af%94-flLVzWbJaa\">\u67e5\u8a62\u8a9e\u6cd5\u7684\u5c0d\u6bd4<\/h2>\n<p>\u5728MySQL\u4e2d\uff0c\u67e5\u8a62\u6578\u64da\u7684\u57fa\u672c\u8a9e\u6cd5\u662f\u4f7f\u7528SELECT\u8a9e\u53e5\uff0c\u800c\u5728MongoDB\u4e2d\uff0c\u67e5\u8a62\u6578\u64da\u5247\u4f7f\u7528find()\u65b9\u6cd5\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u898b\u7684\u67e5\u8a62\u64cd\u4f5c\u5c0d\u6bd4\uff1a<\/p>\n<h3 id=\"%e9%81%b8%e6%93%87%e6%95%b8%e6%93%9a-flLVzWbJaa\">\u9078\u64c7\u6578\u64da<\/h3>\n<p>\u5728MySQL\u4e2d\uff0c\u4f60\u53ef\u4ee5\u9019\u6a23\u9078\u64c7\u6578\u64da\uff1a<\/p>\n<pre><code>\nSELECT * FROM users WHERE email = 'john@example.com';\n<\/code><\/pre>\n<p>\u5728MongoDB\u4e2d\uff0c\u5c0d\u61c9\u7684\u67e5\u8a62\u8a9e\u6cd5\u70ba\uff1a<\/p>\n<pre><code>\ndb.users.find({ email: 'john@example.com' });\n<\/code><\/pre>\n<h3 id=\"%e6%8f%92%e5%85%a5%e6%95%b8%e6%93%9a-flLVzWbJaa\">\u63d2\u5165\u6578\u64da<\/h3>\n<p>\u5728MySQL\u4e2d\uff0c\u63d2\u5165\u6578\u64da\u7684\u8a9e\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre><code>\nINSERT INTO users (name, email) VALUES ('John Doe', 'john@example.com');\n<\/code><\/pre>\n<p>\u800c\u5728MongoDB\u4e2d\uff0c\u63d2\u5165\u6578\u64da\u7684\u8a9e\u6cd5\u70ba\uff1a<\/p>\n<pre><code>\ndb.users.insertOne({ name: 'John Doe', email: 'john@example.com' });\n<\/code><\/pre>\n<h3 id=\"%e6%9b%b4%e6%96%b0%e6%95%b8%e6%93%9a-flLVzWbJaa\">\u66f4\u65b0\u6578\u64da<\/h3>\n<p>\u5728MySQL\u4e2d\uff0c\u66f4\u65b0\u6578\u64da\u7684\u8a9e\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre><code>\nUPDATE users SET email = 'john.doe@example.com' WHERE name = 'John Doe';\n<\/code><\/pre>\n<p>\u5728MongoDB\u4e2d\uff0c\u66f4\u65b0\u6578\u64da\u7684\u8a9e\u6cd5\u70ba\uff1a<\/p>\n<pre><code>\ndb.users.updateOne({ name: 'John Doe' }, { $set: { email: 'john.doe@example.com' } });\n<\/code><\/pre>\n<h2 id=\"%e7%b8%bd%e7%b5%90-flLVzWbJaa\">\u7e3d\u7d50<\/h2>\n<p>\u7e3d\u7684\u4f86\u8aaa\uff0c\u96d6\u7136MySQL\u548cMongoDB\u5728\u6578\u64da\u7d50\u69cb\u548c\u67e5\u8a62\u8a9e\u6cd5\u4e0a\u5b58\u5728\u986f\u8457\u5dee\u7570\uff0c\u4f46\u5982\u679c\u4f60\u5df2\u7d93\u719f\u6089MySQL\u7684SQL\u8a9e\u6cd5\uff0c\u5b78\u7fd2MongoDB\u7684\u67e5\u8a62\u8a9e\u6cd5\u5c07\u6703\u8b8a\u5f97\u76f8\u5c0d\u7c21\u55ae\u3002\u901a\u904e\u7406\u89e3\u5169\u8005\u4e4b\u9593\u7684\u5c0d\u6bd4\uff0c\u4f60\u53ef\u4ee5\u66f4\u5feb\u5730\u638c\u63e1MongoDB\u7684\u4f7f\u7528\u3002<\/p>\n<p>\u5982\u679c\u4f60\u6b63\u5728\u5c0b\u627e\u9ad8\u6548\u7684\u6578\u64da\u5eab\u89e3\u6c7a\u65b9\u6848\uff0c\u8003\u616e\u4f7f\u7528<a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a>\u4f86\u90e8\u7f72\u4f60\u7684\u6578\u64da\u5eab\uff0c\u7121\u8ad6\u662fMySQL\u9084\u662fMongoDB\uff0cServer.HK\u90fd\u80fd\u63d0\u4f9b\u7a69\u5b9a\u7684\u652f\u6301\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b78\u7fd2\u5982\u4f55\u5c07MySQL\u7684SQL\u8a9e\u6cd5\u8f49\u63db\u70baMongoDB\uff0c\u638c\u63e1NoSQL\u6578\u64da\u5eab\u7684\u4f7f\u7528\u6280\u5de7\uff0c\u63d0\u5347\u6578\u64da\u7ba1\u7406\u80fd\u529b\u3002<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-162833","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/162833","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=162833"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/162833\/revisions"}],"predecessor-version":[{"id":162834,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/162833\/revisions\/162834"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=162833"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=162833"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=162833"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}