{"id":185524,"date":"2024-11-10T22:17:19","date_gmt":"2024-11-10T14:17:19","guid":{"rendered":"https:\/\/server.hk\/cnblog\/185524\/"},"modified":"2024-11-10T22:17:20","modified_gmt":"2024-11-10T14:17:20","slug":"%e4%bd%bf%e7%94%a8%e6%8c%87%e5%8d%97%ef%bc%88%e5%b0%8f%e7%a8%8b%e5%ba%8f%e9%9b%b2%e6%95%b8%e6%93%9a%e5%ba%ab%ef%bc%89","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/185524\/","title":{"rendered":"\u4f7f\u7528\u6307\u5357\uff08\u5c0f\u7a0b\u5e8f\u96f2\u6578\u64da\u5eab\uff09"},"content":{"rendered":"<h1 id=\"%e4%bd%bf%e7%94%a8%e6%8c%87%e5%8d%97%ef%bc%88%e5%b0%8f%e7%a8%8b%e5%ba%8f%e9%9b%b2%e6%95%b8%e6%93%9a%e5%ba%ab%ef%bc%89-BYUSVchfWt\">\u4f7f\u7528\u6307\u5357\uff08\u5c0f\u7a0b\u5e8f\u96f2\u6578\u64da\u5eab\uff09<\/h1>\n<p>\u96a8\u8457\u5c0f\u7a0b\u5e8f\u7684\u666e\u53ca\uff0c\u8d8a\u4f86\u8d8a\u591a\u7684\u958b\u767c\u8005\u958b\u59cb\u95dc\u6ce8\u5982\u4f55\u6709\u6548\u5730\u7ba1\u7406\u548c\u5b58\u5132\u6578\u64da\u3002\u96f2\u6578\u64da\u5eab\u4f5c\u70ba\u4e00\u7a2e\u9748\u6d3b\u4e14\u9ad8\u6548\u7684\u89e3\u6c7a\u65b9\u6848\uff0c\u70ba\u5c0f\u7a0b\u5e8f\u7684\u6578\u64da\u7ba1\u7406\u63d0\u4f9b\u4e86\u4fbf\u5229\u3002\u672c\u6587\u5c07\u6df1\u5165\u63a2\u8a0e\u5c0f\u7a0b\u5e8f\u96f2\u6578\u64da\u5eab\u7684\u4f7f\u7528\u6307\u5357\uff0c\u5e6b\u52a9\u958b\u767c\u8005\u66f4\u597d\u5730\u7406\u89e3\u5176\u529f\u80fd\u548c\u61c9\u7528\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%af%e5%b0%8f%e7%a8%8b%e5%ba%8f%e9%9b%b2%e6%95%b8%e6%93%9a%e5%ba%ab%ef%bc%9f-BYUSVchfWt\">\u4ec0\u9ebc\u662f\u5c0f\u7a0b\u5e8f\u96f2\u6578\u64da\u5eab\uff1f<\/h2>\n<p>\u5c0f\u7a0b\u5e8f\u96f2\u6578\u64da\u5eab\u662f\u4e00\u7a2e\u57fa\u65bc\u96f2\u7aef\u7684\u6578\u64da\u5b58\u5132\u89e3\u6c7a\u65b9\u6848\uff0c\u5c08\u70ba\u5c0f\u7a0b\u5e8f\u958b\u767c\u800c\u8a2d\u8a08\u3002\u5b83\u5141\u8a31\u958b\u767c\u8005\u5728\u96f2\u7aef\u5b58\u5132\u548c\u7ba1\u7406\u6578\u64da\uff0c\u4e26\u901a\u904eAPI\u9032\u884c\u8a2a\u554f\u3002\u9019\u7a2e\u65b9\u5f0f\u4e0d\u50c5\u63d0\u9ad8\u4e86\u6578\u64da\u7684\u5b89\u5168\u6027\uff0c\u9084\u80fd\u5920\u5be6\u73fe\u9ad8\u6548\u7684\u6578\u64da\u8b80\u53d6\u548c\u5beb\u5165\u3002<\/p>\n<h2 id=\"%e5%b0%8f%e7%a8%8b%e5%ba%8f%e9%9b%b2%e6%95%b8%e6%93%9a%e5%ba%ab%e7%9a%84%e5%84%aa%e5%8b%a2-BYUSVchfWt\">\u5c0f\u7a0b\u5e8f\u96f2\u6578\u64da\u5eab\u7684\u512a\u52e2<\/h2>\n<ul>\n<li><strong>\u9ad8\u53ef\u7528\u6027\uff1a<\/strong>\u96f2\u6578\u64da\u5eab\u901a\u5e38\u5177\u5099\u81ea\u52d5\u5099\u4efd\u548c\u6062\u5fa9\u529f\u80fd\uff0c\u78ba\u4fdd\u6578\u64da\u7684\u6301\u4e45\u6027\u548c\u53ef\u7528\u6027\u3002<\/li>\n<li><strong>\u64f4\u5c55\u6027\uff1a<\/strong>\u96a8\u8457\u7528\u6236\u6578\u91cf\u7684\u589e\u52a0\uff0c\u96f2\u6578\u64da\u5eab\u53ef\u4ee5\u8f15\u9b06\u64f4\u5c55\uff0c\u6eff\u8db3\u4e0d\u65b7\u589e\u9577\u7684\u9700\u6c42\u3002<\/li>\n<li><strong>\u6210\u672c\u6548\u76ca\uff1a<\/strong>\u4f7f\u7528\u96f2\u6578\u64da\u5eab\u53ef\u4ee5\u6e1b\u5c11\u786c\u9ad4\u6295\u8cc7\uff0c\u958b\u767c\u8005\u53ea\u9700\u70ba\u5be6\u969b\u4f7f\u7528\u7684\u8cc7\u6e90\u4ed8\u8cbb\u3002<\/li>\n<li><strong>\u4fbf\u6377\u7684\u6578\u64da\u7ba1\u7406\uff1a<\/strong>\u958b\u767c\u8005\u53ef\u4ee5\u901a\u904e\u7c21\u55ae\u7684API\u8abf\u7528\u4f86\u9032\u884c\u6578\u64da\u7684\u589e\u522a\u6539\u67e5\uff0c\u7121\u9700\u95dc\u5fc3\u5e95\u5c64\u7684\u6578\u64da\u5b58\u5132\u7d30\u7bc0\u3002<\/li>\n<\/ul>\n<h2 id=\"%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8%e5%b0%8f%e7%a8%8b%e5%ba%8f%e9%9b%b2%e6%95%b8%e6%93%9a%e5%ba%ab-BYUSVchfWt\">\u5982\u4f55\u4f7f\u7528\u5c0f\u7a0b\u5e8f\u96f2\u6578\u64da\u5eab<\/h2>\n<h3 id=\"1-%e8%a8%bb%e5%86%8a%e5%92%8c%e8%a8%ad%e7%bd%ae-BYUSVchfWt\">1. \u8a3b\u518a\u548c\u8a2d\u7f6e<\/h3>\n<p>\u9996\u5148\uff0c\u958b\u767c\u8005\u9700\u8981\u5728\u96f2\u6578\u64da\u5eab\u63d0\u4f9b\u5546\u7684\u7db2\u7ad9\u4e0a\u8a3b\u518a\u4e00\u500b\u5e33\u865f\u3002\u8a3b\u518a\u5b8c\u6210\u5f8c\uff0c\u6839\u64da\u6307\u793a\u5275\u5efa\u4e00\u500b\u65b0\u7684\u6578\u64da\u5eab\u5be6\u4f8b\u3002\u9019\u901a\u5e38\u5305\u62ec\u9078\u64c7\u6578\u64da\u5eab\u985e\u578b\u3001\u914d\u7f6e\u5b58\u5132\u7a7a\u9593\u7b49\u6b65\u9a5f\u3002<\/p>\n<h3 id=\"2-%e6%95%b4%e5%90%88%e5%b0%8f%e7%a8%8b%e5%ba%8f-BYUSVchfWt\">2. \u6574\u5408\u5c0f\u7a0b\u5e8f<\/h3>\n<p>\u5728\u5c0f\u7a0b\u5e8f\u4e2d\u6574\u5408\u96f2\u6578\u64da\u5eab\uff0c\u958b\u767c\u8005\u9700\u8981\u5728\u5c0f\u7a0b\u5e8f\u7684\u914d\u7f6e\u6587\u4ef6\u4e2d\u6dfb\u52a0\u96f2\u6578\u64da\u5eab\u7684\u76f8\u95dc\u4fe1\u606f\u3002\u4ee5\u4e0b\u662f\u4e00\u500b\u7c21\u55ae\u7684\u793a\u4f8b\uff1a<\/p>\n<pre><code>\n{\n  \"cloud\": true,\n  \"env\": \"your-env-id\"\n}\n<\/code><\/pre>\n<h3 id=\"3-%e6%95%b8%e6%93%9a%e6%93%8d%e4%bd%9c-BYUSVchfWt\">3. \u6578\u64da\u64cd\u4f5c<\/h3>\n<p>\u5c0f\u7a0b\u5e8f\u96f2\u6578\u64da\u5eab\u652f\u6301\u591a\u7a2e\u6578\u64da\u64cd\u4f5c\uff0c\u5305\u62ec\u65b0\u589e\u3001\u67e5\u8a62\u3001\u66f4\u65b0\u548c\u522a\u9664\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u57fa\u672c\u7684\u64cd\u4f5c\u793a\u4f8b\uff1a<\/p>\n<h4 id=\"%e6%96%b0%e5%a2%9e%e6%95%b8%e6%93%9a-BYUSVchfWt\">\u65b0\u589e\u6578\u64da<\/h4>\n<pre><code>\nconst db = wx.cloud.database();\ndb.collection('your-collection').add({\n  data: {\n    name: 'John Doe',\n    age: 30\n  },\n  success: function(res) {\n    console.log('\u65b0\u589e\u6210\u529f', res);\n  },\n  fail: function(err) {\n    console.error('\u65b0\u589e\u5931\u6557', err);\n  }\n});\n<\/code><\/pre>\n<h4 id=\"%e6%9f%a5%e8%a9%a2%e6%95%b8%e6%93%9a-BYUSVchfWt\">\u67e5\u8a62\u6578\u64da<\/h4>\n<pre><code>\ndb.collection('your-collection').where({\n  age: 30\n}).get({\n  success: function(res) {\n    console.log('\u67e5\u8a62\u6210\u529f', res.data);\n  },\n  fail: function(err) {\n    console.error('\u67e5\u8a62\u5931\u6557', err);\n  }\n});\n<\/code><\/pre>\n<h4 id=\"%e6%9b%b4%e6%96%b0%e6%95%b8%e6%93%9a-BYUSVchfWt\">\u66f4\u65b0\u6578\u64da<\/h4>\n<pre><code>\ndb.collection('your-collection').doc('document-id').update({\n  data: {\n    age: 31\n  },\n  success: function(res) {\n    console.log('\u66f4\u65b0\u6210\u529f', res);\n  },\n  fail: function(err) {\n    console.error('\u66f4\u65b0\u5931\u6557', err);\n  }\n});\n<\/code><\/pre>\n<h4 id=\"%e5%88%aa%e9%99%a4%e6%95%b8%e6%93%9a-BYUSVchfWt\">\u522a\u9664\u6578\u64da<\/h4>\n<pre><code>\ndb.collection('your-collection').doc('document-id').remove({\n  success: function(res) {\n    console.log('\u522a\u9664\u6210\u529f', res);\n  },\n  fail: function(err) {\n    console.error('\u522a\u9664\u5931\u6557', err);\n  }\n});\n<\/code><\/pre>\n<h2 id=\"%e7%b8%bd%e7%b5%90-BYUSVchfWt\">\u7e3d\u7d50<\/h2>\n<p>\u5c0f\u7a0b\u5e8f\u96f2\u6578\u64da\u5eab\u70ba\u958b\u767c\u8005\u63d0\u4f9b\u4e86\u4e00\u500b\u9ad8\u6548\u3001\u9748\u6d3b\u7684\u6578\u64da\u7ba1\u7406\u89e3\u6c7a\u65b9\u6848\u3002\u901a\u904e\u7c21\u55ae\u7684API\u8abf\u7528\uff0c\u958b\u767c\u8005\u53ef\u4ee5\u8f15\u9b06\u5730\u9032\u884c\u6578\u64da\u7684\u589e\u522a\u6539\u67e5\uff0c\u4e26\u4eab\u53d7\u96f2\u7aef\u5e36\u4f86\u7684\u9ad8\u53ef\u7528\u6027\u548c\u64f4\u5c55\u6027\u3002\u5982\u679c\u60a8\u6b63\u5728\u5c0b\u627e\u53ef\u9760\u7684 <a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a> \u89e3\u6c7a\u65b9\u6848\uff0cServer.HK \u63d0\u4f9b\u591a\u7a2e\u9078\u64c7\uff0c\u6eff\u8db3\u4e0d\u540c\u9700\u6c42\u7684\u7528\u6236\u3002\u7121\u8ad6\u662f\u5c0f\u578b\u9805\u76ee\u9084\u662f\u5927\u578b\u61c9\u7528\uff0c\u60a8\u90fd\u53ef\u4ee5\u5728\u9019\u88e1\u627e\u5230\u5408\u9069\u7684 <a href=\"https:\/\/server.hk\">\u96f2\u4f3a\u670d\u5668<\/a> \u65b9\u6848\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u63a2\u7d22\u5c0f\u7a0b\u5e8f\u4e91\u6570\u636e\u5e93\u7684\u4f7f\u7528\u6307\u5357\uff0c\u83b7\u53d6\u64cd\u4f5c\u6b65\u9aa4\u3001\u6700\u4f73\u5b9e\u8df5\u548c\u5e38\u89c1\u95ee\u9898\u89e3\u7b54\uff0c\u8f7b\u677e\u7ba1\u7406\u60a8\u7684\u6570\u636e\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-185524","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/185524","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=185524"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/185524\/revisions"}],"predecessor-version":[{"id":185525,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/185524\/revisions\/185525"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=185524"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=185524"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=185524"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}