{"id":185043,"date":"2023-09-15T20:21:19","date_gmt":"2023-09-15T12:21:19","guid":{"rendered":"http:\/\/www.idc.net\/help\/185043\/"},"modified":"2023-09-15T20:21:19","modified_gmt":"2023-09-15T12:21:19","slug":"%e5%90%8e%e6%b5%aa%e4%ba%91%e5%b0%8f%e7%a8%8b%e5%ba%8f%e6%95%99%e7%a8%8b%ef%bc%9a%e5%be%ae%e4%bf%a1%e5%b0%8f%e7%a8%8b%e5%ba%8f%e4%ba%91%e5%bc%80%e5%8f%91%e6%9c%8d%e5%8a%a1%e7%ab%af%e6%95%b0%e6%8d%ae-4","status":"publish","type":"post","link":"https:\/\/idc.net\/help\/185043\/","title":{"rendered":"\u540e\u6d6a\u4e91\u5c0f\u7a0b\u5e8f\u6559\u7a0b\uff1a\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u4e91\u5f00\u53d1\u670d\u52a1\u7aef\u6570\u636e\u5e93API \u66f4\u65b0\u6307\u4ee4"},"content":{"rendered":"<h2>db.command.set<\/h2>\n<p>\u66f4\u65b0\u6307\u4ee4\u3002\u7528\u4e8e\u8bbe\u5b9a\u5b57\u6bb5\u7b49\u4e8e\u6307\u5b9a\u503c\u3002<\/p>\n<p>\u51fd\u6570\u7b7e\u540d\uff1a<\/p>\n<pre><code>function set(value: any): Command\n<\/code><\/pre>\n<p>\u8fd9\u79cd\u65b9\u6cd5\u76f8\u6bd4\u4f20\u5165\u7eaf JS \u5bf9\u8c61\u7684\u597d\u5904\u662f\u80fd\u591f\u6307\u5b9a\u5b57\u6bb5\u7b49\u4e8e\u4e00\u4e2a\u5bf9\u8c61\uff1a<\/p>\n<pre><code>const cloud = require('wx-server-sdk')\ncloud.init()\nconst db = cloud.database()\nexports.main = async (event, context) =&gt; {\n  try {\n    \/\/ \u4ee5\u4e0b\u65b9\u6cd5\u53ea\u4f1a\u66f4\u65b0 style.color \u4e3a red\uff0c\u800c\u4e0d\u662f\u5c06 style \u66f4\u65b0\u4e3a { color: 'red' }\uff0c\u5373\u4e0d\u5f71\u54cd style \u4e2d\u7684\u5176\u4ed6\u5b57\u6bb5\n    const res1 = await db.collection('todos').doc('doc-id').update({\n      data: {\n        style: {\n          color: 'red'\n        }\n      }\n    })\n\n    \/\/ \u4ee5\u4e0b\u65b9\u6cd5\u66f4\u65b0 style \u4e3a { color: 'red', size: 'large' }\n    const res2 = await db.collection('todos').doc('doc-id').update({\n      data: {\n        style: _.set({\n          color: 'red',\n          size: 'large'\n        })\n      }\n    })\n\n    return {\n      res1,\n      res2,\n    }\n  } catch(e) {\n    console.error(e)\n  }\n}<\/code><\/pre>\n<hr>\n<h2>db.command.remove<\/h2>\n<p>\u66f4\u65b0\u6307\u4ee4\u3002\u7528\u4e8e\u8868\u793a\u5220\u9664\u67d0\u4e2a\u5b57\u6bb5\u3002<\/p>\n<p>\u51fd\u6570\u7b7e\u540d\uff1a<\/p>\n<pre><code>function remove(): Command\n<\/code><\/pre>\n<p>\u793a\u4f8b\u4ee3\u7801<\/p>\n<p>\u5220\u9664 style \u5b57\u6bb5\uff1a<\/p>\n<pre><code>const cloud = require('wx-server-sdk')\ncloud.init()\nconst db = cloud.database()\nconst _ = db.command\nexports.main = async (event, context) =&gt; {\n  try {\n    return await db.collection('todos').doc('todo-id').update({\n      data: {\n        style: _.remove()\n      }\n    })\n  } catch(e) {\n    console.error(e)\n  }\n}<\/code><\/pre>\n<hr>\n<h2>db.command.inc<\/h2>\n<p>\u66f4\u65b0\u6307\u4ee4\u3002\u7528\u4e8e\u6307\u793a\u5b57\u6bb5\u81ea\u589e\u67d0\u4e2a\u503c\uff0c\u8fd9\u662f\u4e2a\u539f\u5b50\u64cd\u4f5c\uff0c\u4f7f\u7528\u8fd9\u4e2a\u64cd\u4f5c\u6307\u4ee4\u800c\u4e0d\u662f\u5148\u8bfb\u6570\u636e\u3001\u518d\u52a0\u3001\u518d\u5199\u56de\u7684\u597d\u5904\u662f\uff1a<\/p>\n<ol>\n<li>\u539f\u5b50\u6027\uff1a\u591a\u4e2a\u7528\u6237\u540c\u65f6\u5199\uff0c\u5bf9\u6570\u636e\u5e93\u6765\u8bf4\u90fd\u662f\u5c06\u5b57\u6bb5\u52a0\u4e00\uff0c\u4e0d\u4f1a\u6709\u540e\u6765\u8005\u8986\u5199\u524d\u8005\u7684\u60c5\u51b5<\/li>\n<li>\u51cf\u5c11\u4e00\u6b21\u7f51\u7edc\u8bf7\u6c42\uff1a\u4e0d\u9700\u5148\u8bfb\u518d\u5199<\/li>\n<\/ol>\n<p>mul&nbsp;\u6307\u4ee4\u540c\u7406\u3002<\/p>\n<p>\u51fd\u6570\u7b7e\u540d\uff1a<\/p>\n<pre><code>function inc(value: number): Command\n<\/code><\/pre>\n<p>\u793a\u4f8b\u4ee3\u7801<\/p>\n<p>\u5c06\u4e00\u4e2a todo \u7684\u8fdb\u5ea6\u81ea\u589e 10\uff1a<\/p>\n<pre><code>const cloud = require('wx-server-sdk')\ncloud.init()\nconst db = cloud.database()\nconst _ = db.command\nexports.main = async (event, context) =&gt; {\n  try {\n    return await db.collection('todos').doc('todo-id').update({\n      data: {\n        progress: _.inc(10)\n      }\n    })\n  } catch(e) {\n    console.error(e)\n  }\n}<\/code><\/pre>\n<hr>\n<h2>db.command.mul<\/h2>\n<p>\u66f4\u65b0\u6307\u4ee4\u3002\u7528\u4e8e\u6307\u793a\u5b57\u6bb5\u81ea\u4e58\u67d0\u4e2a\u503c\uff0c\u8fd9\u662f\u4e2a\u539f\u5b50\u64cd\u4f5c\uff0c\u4f7f\u7528\u8fd9\u4e2a\u64cd\u4f5c\u6307\u4ee4\u800c\u4e0d\u662f\u5148\u8bfb\u6570\u636e\u3001\u518d\u52a0\u3001\u518d\u5199\u56de\u7684\u597d\u5904\u662f\uff1a<\/p>\n<ol>\n<li>\u539f\u5b50\u6027\uff1a\u591a\u4e2a\u7528\u6237\u540c\u65f6\u5199\uff0c\u5bf9\u6570\u636e\u5e93\u6765\u8bf4\u90fd\u662f\u5c06\u5b57\u6bb5\u81ea\u4e58\uff0c\u4e0d\u4f1a\u6709\u540e\u6765\u8005\u8986\u5199\u524d\u8005\u7684\u60c5\u51b5<\/li>\n<li>\u51cf\u5c11\u4e00\u6b21\u7f51\u7edc\u8bf7\u6c42\uff1a\u4e0d\u9700\u5148\u8bfb\u518d\u5199<\/li>\n<\/ol>\n<p>inc&nbsp;\u6307\u4ee4\u540c\u7406\u3002<\/p>\n<p>\u51fd\u6570\u7b7e\u540d\uff1a<\/p>\n<pre><code>function mul(value: number): Command\n<\/code><\/pre>\n<p>\u793a\u4f8b\u4ee3\u7801<\/p>\n<p>\u5c06\u4e00\u4e2a todo \u7684\u8fdb\u5ea6\u4e58 2\uff1a<\/p>\n<pre><code>const cloud = require('wx-server-sdk')\ncloud.init()\nconst db = cloud.database()\nconst _ = db.command\nexports.main = async (event, context) =&gt; {\n  try {\n    return await db.collection('todos').doc('todo-id').update({\n      data: {\n        progress: _.mul(2)\n      }\n    })\n  } catch(e) {\n    console.error(e)\n  }\n}<\/code><\/pre>\n<hr>\n<h2>db.command.push<\/h2>\n<p>\u66f4\u65b0\u6307\u4ee4\uff0c\u5bf9\u4e00\u4e2a\u503c\u4e3a\u6570\u7ec4\u7684\u5b57\u6bb5\uff0c\u5f80\u6570\u7ec4\u5c3e\u90e8\u6dfb\u52a0\u4e00\u4e2a\u6216\u591a\u4e2a\u503c\u3002\u6216\u5b57\u6bb5\u539f\u4e3a\u7a7a\uff0c\u5219\u521b\u5efa\u8be5\u5b57\u6bb5\u5e76\u8bbe\u6570\u7ec4\u4e3a\u4f20\u5165\u503c\u3002<\/p>\n<p>\u51fd\u6570\u7b7e\u540d\uff1a<\/p>\n<pre><code>function push(values: any[]): Command\n<\/code><\/pre>\n<p>\u793a\u4f8b\u4ee3\u7801<\/p>\n<pre><code>const cloud = require('wx-server-sdk')\ncloud.init()\nconst db = cloud.database()\nconst _ = db.command\nexports.main = async (event, context) =&gt; {\n  try {\n    return await db.collection('todos').doc('doc-id').update({\n      data: {\n        tags: _.push(['mini-program', 'cloud'])\n      }\n    })\n  } catch(e) {\n    console.error(e)\n  }\n}<\/code><\/pre>\n<hr>\n<h2>db.command.pop<\/h2>\n<p>\u66f4\u65b0\u6307\u4ee4\uff0c\u5bf9\u4e00\u4e2a\u503c\u4e3a\u6570\u7ec4\u7684\u5b57\u6bb5\uff0c\u5c06\u6570\u7ec4\u5c3e\u90e8\u5143\u7d20\u5220\u9664\u3002<\/p>\n<p>\u51fd\u6570\u7b7e\u540d\uff1a<\/p>\n<pre><code>function pop(values: any[]): Command\n<\/code><\/pre>\n<p>\u793a\u4f8b\u4ee3\u7801<\/p>\n<pre><code>const cloud = require('wx-server-sdk')\ncloud.init()\nconst db = cloud.database()\nconst _ = db.command\nexports.main = async (event, context) =&gt; {\n  try {\n    return await db.collection('todos').doc('doc-id').update({\n      data: {\n        tags: _.pop()\n      }\n    })\n  } catch(e) {\n    console.error(e)\n  }\n}<\/code><\/pre>\n<hr>\n<h2>db.command.shift<\/h2>\n<p>\u66f4\u65b0\u6307\u4ee4\uff0c\u5bf9\u4e00\u4e2a\u503c\u4e3a\u6570\u7ec4\u7684\u5b57\u6bb5\uff0c\u5c06\u6570\u7ec4\u5934\u90e8\u5143\u7d20\u5220\u9664\u3002<\/p>\n<p>\u51fd\u6570\u7b7e\u540d\uff1a<\/p>\n<pre><code>function shift(values: any[]): Command\n<\/code><\/pre>\n<p>\u793a\u4f8b\u4ee3\u7801<\/p>\n<pre><code>const cloud = require('wx-server-sdk')\ncloud.init()\nconst db = cloud.database()\nconst _ = db.command\nexports.main = async (event, context) =&gt; {\n  try {\n    return await db.collection('todos').doc('doc-id').update({\n      data: {\n        tags: _.shift()\n      }\n    })\n  } catch(e) {\n    console.error(e)\n  }\n}<\/code><\/pre>\n<hr>\n<h2>db.command.unshift<\/h2>\n<p>\u66f4\u65b0\u6307\u4ee4\uff0c\u5bf9\u4e00\u4e2a\u503c\u4e3a\u6570\u7ec4\u7684\u5b57\u6bb5\uff0c\u5f80\u6570\u7ec4\u5934\u90e8\u6dfb\u52a0\u4e00\u4e2a\u6216\u591a\u4e2a\u503c\u3002\u6216\u5b57\u6bb5\u539f\u4e3a\u7a7a\uff0c\u5219\u521b\u5efa\u8be5\u5b57\u6bb5\u5e76\u8bbe\u6570\u7ec4\u4e3a\u4f20\u5165\u503c\u3002<\/p>\n<p>\u51fd\u6570\u7b7e\u540d\uff1a<\/p>\n<pre><code>function unshift(values: any[]): Command\n<\/code><\/pre>\n<p>\u793a\u4f8b\u4ee3\u7801<\/p>\n<pre><code>const cloud = require('wx-server-sdk')\ncloud.init()\nconst db = cloud.database()\nconst _ = db.command\nexports.main = async (event, context) =&gt; {\n  try {\n    return await db.collection('todos').doc('doc-id').update({\n      data: {\n        tags: _.unshift(['mini-program', 'cloud'])\n      }\n    })\n  } catch(e) {\n    console.error(e)\n  }\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>db.command.set \u66f4\u65b0\u6307\u4ee4\u3002\u7528\u4e8e\u8bbe\u5b9a\u5b57\u6bb5\u7b49\u4e8e\u6307\u5b9a\u503c\u3002 \u51fd\u6570\u7b7e\u540d\uff1a function set(val [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[182398],"tags":[],"class_list":["post-185043","post","type-post","status-publish","format-standard","hentry","category-mini-program"],"_links":{"self":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/185043","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/comments?post=185043"}],"version-history":[{"count":0,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/185043\/revisions"}],"wp:attachment":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/media?parent=185043"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/categories?post=185043"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/tags?post=185043"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}