{"id":159310,"date":"2020-09-23T06:58:40","date_gmt":"2020-09-22T22:58:40","guid":{"rendered":"http:\/\/4563.org\/?p=159310"},"modified":"2020-09-23T06:58:40","modified_gmt":"2020-09-22T22:58:40","slug":"mongoose-%e8%81%9a%e5%90%88%e7%ae%a1%e9%81%93%e6%9f%a5%e8%af%a2%ef%bc%8c-list-%e4%b8%ad%e7%9a%84%e5%ad%90%e5%af%b9%e8%b1%a1%e5%a6%82%e4%bd%95%e5%85%b3%e8%81%94%ef%bc%9f","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=159310","title":{"rendered":"mongoose \u805a\u5408\u7ba1\u9053\u67e5\u8be2\uff0c list \u4e2d\u7684\u5b50\u5bf9\u8c61\u5982\u4f55\u5173\u8054\uff1f"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  mongoose \u805a\u5408\u7ba1\u9053\u67e5\u8be2\uff0c list \u4e2d\u7684\u5b50\u5bf9\u8c61\u5982\u4f55\u5173\u8054\uff1f               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : ideacco <\/span>  <span><i><\/i> 0<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>RT\uff0c\u4f7f\u7528 mongoose\uff0c\u6709\u5982\u4e0b\u4e24\u4e2a\u6570\u636e\uff0c\u6211\u60f3\u628a\u4ea7\u54c1\u53c2\u6570\u636e\u8868\uff0c\u5bf9\u5e94\u7684\u4ea7\u54c1\u67e5\u8be2\u51fa\u6765\uff0c\u6211\u76ee\u524d\u53ea\u4f1a\u67e5\u8be2\u4e00\u7ea7\u7684\uff0c\u5728 Array \u91cc\u9762\u5305\u88f9\u7684\u6570\u636e\u5c31\u4e0d\u77e5\u9053\u600e\u4e48\u53d6\u51fa\u6765\u4e86\uff0c\u770b\u4e86\u4e00\u5929\u7684\u5b98\u7f51\u6587\u6863\u4e5f\u6ca1\u770b\u660e\u767d\u2026\u2026\u60ed\u6127\u60ed\u6127\uff0c\u6c42\u5927\u795e\u7ed9\u6307\u4e2a\u9053\u5427\u3002<\/p>\n<p>\u793a\u4f8b\u6570\u636e\u5982\u4e0b\uff1a<\/p>\n<pre><code>\/\/ \u4ea7\u54c1\u6570\u636e\u8868 product {     \"uid\": \"5f460572f639b62baa839baa\",     \"productCounts\": 17,     \"productItems\": [{             \"is_variants\": false,             \"totalVariants\": 1,             \"id\": 12345 \"tetle\": \"\u82f9\u679c\"         },         {             \"is_variants\": false,             \"totalVariants\": 1,             \"id\": 23456 \"tetle\": \"\u897f\u74dc\"         },         {             \"is_variants\": false,             \"totalVariants\": 1,             \"id\": 56789 \"tetle\": \"\u8354\u679d\"         },         ...     ]  }  \/\/ \u4ea7\u54c1\u53c2\u6570\u6570\u636e\u8868 options  {        \"uid\": \"5f460572f639b62baa839baa\",     \"pid\":23456,     \"ditch\": \"weixin\",     \"postcode\": 518000,     \"is_pay\": true } <\/code><\/pre>\n<p>\u6211\u60f3\u8981\u7684\u6570\u636e\u5982\u4e0b<\/p>\n<pre><code>{     \"is_variants\": false,     \"totalVariants\": 1,     \"id\": 12345,     \"tetle\": \"\u82f9\u679c\",     \"options\": {         \"uid\": \"5f460572f639b62baa839baa\",         \"pid\": 23456,         \"ditch\": \"weixin\",         \"postcode\": 518000,         \"is_pay\": true     } } <\/code><\/pre>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>7<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"3427458\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : ScaredHeart <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5148\u901a\u8fc7[$unwind]( https:\/\/docs.mongodb.com\/manual\/reference\/operator\/aggregation\/unwind\/index.html)\u628a\u6570\u7ec4\u4e2d\u7684\u5143\u7d20\u62c6\u5206\uff0c[$project]( https:\/\/docs.mongodb.com\/manual\/reference\/operator\/aggregation\/project\/index.html)\u4fee\u526a\u4e0b\u6570\u636e\uff0c\u5bf9 uid \u5b57\u6bb5[$lookup]( https:\/\/docs.mongodb.com\/manual\/reference\/operator\/aggregation\/lookup\/index.html)\u6765\u5173\u8054 options \u8868(uid \u662f objectId \u7684\u8bdd                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3427459\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : wkzq <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             &#8220;&#8220;<br \/>db.getCollection(&#8217;emotes&#8217;).aggregate([<br \/>{$match: {&#8220;productItems.id&#8221;: 23456}},<br \/>{$unwind: &#8220;$productItems&#8221;},<br \/>{$match: {&#8220;productItems.id&#8221;: 23456}},<br \/>{<br \/> $lookup:<br \/> {<br \/> from: &#8220;options&#8221;,<br \/> localField: &#8220;productItems.id&#8221;,<br \/> foreignField: &#8220;pid&#8221;,<br \/> as: &#8220;options&#8221;<br \/> }<br \/>},<br \/>{$unwind: &#8220;$options&#8221;},<br \/>{<br \/> $project: {<br \/> &#8220;is_variants&#8221;: &#8220;$productItems.is_variants&#8221;,<br \/> &#8220;totalVariants&#8221;: &#8220;$productItems.totalVariants&#8221;,<br \/> &#8220;id&#8221;: &#8220;$productItems.id&#8221;,<br \/> &#8220;tetle&#8221;: &#8220;$productItems.tetle&#8221;,<br \/> &#8220;options&#8221;: 1<br \/> }<br \/>}<br \/>])<br \/>&#8220;&#8220;<br \/>\u9700\u8981\u7ed9`productItems.id`\u52a0\u7d22\u5f15                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3427460\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : wkzq <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u56de\u590d\u4e0d\u652f\u6301 md, \u7528\u8fd9\u4e2a\u5427<br \/>https:\/\/gist.github.com\/fefine\/d5fd3d60688d05887316ae25322f50f5 <button onclick=\"lazyGist(this)\">\u00a0\u663e\u793a Gist \u4ee3\u7801\u00a0<\/button> <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3427461\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : ideacco <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @ScaredHeart \u611f\u8c22\u56de\u590d                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3427462\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : ideacco <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @wkzq \u611f\u8c22\u60a8\u7684\u56de\u590d\uff0c\u8c22\u8c22                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3427463\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : ideacco <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @wkzq \u611f\u8c22\u56de\u590d                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3427464\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : ideacco <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @wkzq \u5144\u5f1f\u4f60\u8fd9\u592a\u5389\u5bb3\u4e86\uff0c\u611f\u8c22\u611f\u8c22\uff0c\u62b1\u62f3\uff01\uff01                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>mongoose \u805a\u5408\u7ba1\u9053\u67e5\u8be2\uff0c &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/159310"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=159310"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/159310\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=159310"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=159310"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=159310"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}