{"id":184949,"date":"2022-09-04T10:31:41","date_gmt":"2022-09-04T02:31:41","guid":{"rendered":"http:\/\/www.idc.net\/help\/184949\/"},"modified":"2022-09-04T10:31:41","modified_gmt":"2022-09-04T02:31:41","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%9asdk%e6%95%b0%e6%8d%ae%e5%ba%93-collection%c2%b7%e6%9e%84%e5%bb%ba%e6%9f%a5%e8%af%a2%e6%9d%a1%e4%bb%b6","status":"publish","type":"post","link":"https:\/\/idc.net\/help\/184949\/","title":{"rendered":"\u540e\u6d6a\u4e91\u5c0f\u7a0b\u5e8f\u6559\u7a0b\uff1aSDK\u6570\u636e\u5e93 Collection\u00b7\u6784\u5efa\u67e5\u8be2\u6761\u4ef6"},"content":{"rendered":"<h2>Collection.where(condition: Object):&nbsp;Collection<\/h2>\n<h2>\n<blockquote><p>\n   \u652f\u6301\u7aef\uff1a\u5c0f\u7a0b\u5e8f&nbsp;,&nbsp;\u4e91\u51fd\u6570&nbsp;,&nbsp;Web\n <\/p><\/blockquote>\n<p>\u6307\u5b9a\u67e5\u8be2\u6761\u4ef6\uff0c\u8fd4\u56de\u5e26\u65b0\u67e5\u8be2\u6761\u4ef6\u7684\u65b0\u7684\u96c6\u5408\u5f15\u7528<\/p>\n<\/h2>\n<h2>\u53c2\u6570<\/h2>\n<h3>condition: Object<\/h3>\n<h2>\n<p>\u67e5\u8be2\u6761\u4ef6<\/p>\n<\/h2>\n<h2>\u8fd4\u56de\u503c<\/h2>\n<h3>Collection<\/h3>\n<h2>\u793a\u4f8b\u4ee3\u7801<\/h2>\n<h2>\n<pre><code>const _ = db.command\nconst result = await db.collection('todos').where({\n  price: _.lt(100)\n}).get()<\/code><\/pre>\n<\/h2>\n<hr>\n<h2>Collection.limit(value: number):&nbsp;Collection<\/h2>\n<blockquote><p>\n  \u652f\u6301\u7aef\uff1a\u5c0f\u7a0b\u5e8f&nbsp;,&nbsp;\u4e91\u51fd\u6570&nbsp;,&nbsp;Web\n<\/p><\/blockquote>\n<p>\u6307\u5b9a\u67e5\u8be2\u7ed3\u679c\u96c6\u6570\u91cf\u4e0a\u9650<\/p>\n<h2>\u53c2\u6570<\/h2>\n<h3>value: number<\/h3>\n<h2>\u8fd4\u56de\u503c<\/h2>\n<h3>Collection<\/h3>\n<h2>\u8bf4\u660e<\/h2>\n<p>limit&nbsp;\u5728\u5c0f\u7a0b\u5e8f\u7aef\u9ed8\u8ba4\u53ca\u6700\u5927\u4e0a\u9650\u4e3a 20\uff0c\u5728\u4e91\u51fd\u6570\u7aef\u9ed8\u8ba4\u53ca\u6700\u5927\u4e0a\u9650\u4e3a 1000<\/p>\n<h2>\u793a\u4f8b\u4ee3\u7801<\/h2>\n<pre><code>db.collection('todos').limit(10)\n  .get()\n  .then(console.log)\n  .catch(console.error)<\/code><\/pre>\n<hr>\n<h2>Collection.orderBy(fieldPath: string, string: order):&nbsp;Collection<\/h2>\n<blockquote><p>\n  \u652f\u6301\u7aef\uff1a\u5c0f\u7a0b\u5e8f&nbsp;,&nbsp;\u4e91\u51fd\u6570&nbsp;,&nbsp;Web\n<\/p><\/blockquote>\n<p>\u6307\u5b9a\u67e5\u8be2\u6392\u5e8f\u6761\u4ef6<\/p>\n<h2>\u53c2\u6570<\/h2>\n<h3>fieldPath: string<\/h3>\n<h3>string: order<\/h3>\n<h2>\u8fd4\u56de\u503c<\/h2>\n<h3>Collection<\/h3>\n<h2>\u8bf4\u660e<\/h2>\n<p>\u65b9\u6cd5\u63a5\u53d7\u4e00\u4e2a\u5fc5\u586b\u5b57\u7b26\u4e32\u53c2\u6570 fieldName \u7528\u4e8e\u5b9a\u4e49\u9700\u8981\u6392\u5e8f\u7684\u5b57\u6bb5\uff0c\u4e00\u4e2a\u5b57\u7b26\u4e32\u53c2\u6570 order \u5b9a\u4e49\u6392\u5e8f\u987a\u5e8f\u3002order \u53ea\u80fd\u53d6&nbsp;asc&nbsp;\u6216&nbsp;desc\u3002<\/p>\n<p>\u5982\u679c\u9700\u8981\u5bf9\u5d4c\u5957\u5b57\u6bb5\u6392\u5e8f\uff0c\u9700\u8981\u7528 \"\u70b9\u8868\u793a\u6cd5\" \u8fde\u63a5\u5d4c\u5957\u5b57\u6bb5\uff0c\u6bd4\u5982&nbsp;style.color&nbsp;\u8868\u793a\u5b57\u6bb5&nbsp;style&nbsp;\u91cc\u7684\u5d4c\u5957\u5b57\u6bb5&nbsp;color\u3002<\/p>\n<p>\u540c\u65f6\u4e5f\u652f\u6301\u6309\u591a\u4e2a\u5b57\u6bb5\u6392\u5e8f\uff0c\u591a\u6b21\u8c03\u7528&nbsp;orderBy&nbsp;\u5373\u53ef\uff0c\u591a\u5b57\u6bb5\u6392\u5e8f\u65f6\u7684\u987a\u5e8f\u4f1a\u6309\u7167&nbsp;orderBy&nbsp;\u8c03\u7528\u987a\u5e8f\u5148\u540e\u5bf9\u591a\u4e2a\u5b57\u6bb5\u6392\u5e8f<\/p>\n<h2>\u793a\u4f8b\u4ee3\u7801\uff1a\u6309\u4e00\u4e2a\u5b57\u6bb5\u6392\u5e8f<\/h2>\n<p>\u6309\u8fdb\u5ea6\u6392\u5347\u5e8f\u53d6\u5f85\u529e\u4e8b\u9879<\/p>\n<pre><code>db.collection('todos').orderBy('progress', 'asc')\n  .get()\n  .then(console.log)\n  .catch(console.error)\n<\/code><\/pre>\n<h2>\u793a\u4f8b\u4ee3\u7801\uff1a\u6309\u591a\u4e2a\u5b57\u6bb5\u6392\u5e8f<\/h2>\n<p>\u5148\u6309 progress \u6392\u964d\u5e8f\uff08progress \u8d8a\u5927\u8d8a\u9760\u524d\uff09\u3001\u518d\u6309 description \u6392\u5347\u5e8f\uff08\u5b57\u6bcd\u5e8f\u8d8a\u524d\u8d8a\u9760\u524d\uff09\u53d6\u5f85\u529e\u4e8b\u9879\uff1a<\/p>\n<pre><code>db.collection('todos')\n  .orderBy('progress', 'desc')\n  .orderBy('description', 'asc')\n  .get()\n  .then(console.log)\n  .catch(console.error)<\/code><\/pre>\n<hr>\n<h2>Collection.skip(offset: number):&nbsp;Collection<\/h2>\n<blockquote><p>\n  \u652f\u6301\u7aef\uff1a\u5c0f\u7a0b\u5e8f&nbsp;,&nbsp;\u4e91\u51fd\u6570&nbsp;,&nbsp;Web\n<\/p><\/blockquote>\n<p>\u6307\u5b9a\u67e5\u8be2\u8fd4\u56de\u7ed3\u679c\u65f6\u4ece\u6307\u5b9a\u5e8f\u5217\u540e\u7684\u7ed3\u679c\u5f00\u59cb\u8fd4\u56de\uff0c\u5e38\u7528\u4e8e\u5206\u9875<\/p>\n<h2>\u53c2\u6570<\/h2>\n<h3>offset: number<\/h3>\n<h2>\u8fd4\u56de\u503c<\/h2>\n<h3>Collection<\/h3>\n<h2>\u793a\u4f8b\u4ee3\u7801<\/h2>\n<pre><code>db.collection('todos').skip(10)\n  .get()\n  .then(console.log)\n  .catch(console.error)<\/code><\/pre>\n<hr>\n<h2>Collection.field(projection: Object):&nbsp;Collection<\/h2>\n<blockquote><p>\n  \u652f\u6301\u7aef\uff1a\u5c0f\u7a0b\u5e8f&nbsp;,&nbsp;\u4e91\u51fd\u6570&nbsp;,&nbsp;Web\n<\/p><\/blockquote>\n<p>\u6307\u5b9a\u8fd4\u56de\u7ed3\u679c\u4e2d\u8bb0\u5f55\u9700\u8fd4\u56de\u7684\u5b57\u6bb5<\/p>\n<h2>\u53c2\u6570<\/h2>\n<h3>projection: Object<\/h3>\n<h2>\u8fd4\u56de\u503c<\/h2>\n<h3>Collection<\/h3>\n<h2>\u8bf4\u660e<\/h2>\n<p>\u65b9\u6cd5\u63a5\u53d7\u4e00\u4e2a\u5fc5\u586b\u5bf9\u8c61\u7528\u4e8e\u6307\u5b9a\u9700\u8fd4\u56de\u7684\u5b57\u6bb5\uff0c\u5bf9\u8c61\u7684\u5404\u4e2a key \u8868\u793a\u8981\u8fd4\u56de\u6216\u4e0d\u8981\u8fd4\u56de\u7684\u5b57\u6bb5\uff0cvalue \u4f20\u5165 true|false\uff08\u6216 1|-1\uff09\u8868\u793a\u8981\u8fd4\u56de\u8fd8\u662f\u4e0d\u8981\u8fd4\u56de\u3002<\/p>\n<h2>\u793a\u4f8b\u4ee3\u7801<\/h2>\n<p>\u53ea\u8fd4\u56de description, done \u548c progress \u4e09\u4e2a\u5b57\u6bb5\uff1a<\/p>\n<pre><code>db.collection('todos').field({\n  description: true,\n  done: true,\n  progress: true,\n})\n  .get()\n  .then(console.log)\n  .catch(console.error)<\/code><\/pre>\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Collection.where(condition: Object):&nbsp;Collection \u652f\u6301 [&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-184949","post","type-post","status-publish","format-standard","hentry","category-mini-program"],"_links":{"self":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/184949","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=184949"}],"version-history":[{"count":0,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/184949\/revisions"}],"wp:attachment":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/media?parent=184949"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/categories?post=184949"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/tags?post=184949"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}