{"id":152552,"date":"2020-09-07T02:22:54","date_gmt":"2020-09-06T18:22:54","guid":{"rendered":"http:\/\/4563.org\/?p=152552"},"modified":"2020-09-07T02:22:54","modified_gmt":"2020-09-06T18:22:54","slug":"%e8%af%b7%e9%97%ae%e8%bf%99%e4%b8%80%e6%ad%a5%e4%b8%ba%e5%95%a5%e8%a6%81%e5%88%86-2-%e6%ac%a1%e5%86%99%ef%bc%9f","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=152552","title":{"rendered":"\u8bf7\u95ee\u8fd9\u4e00\u6b65\u4e3a\u5565\u8981\u5206 2 \u6b21\u5199\uff1f"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  \u8bf7\u95ee\u8fd9\u4e00\u6b65\u4e3a\u5565\u8981\u5206 2 \u6b21\u5199\uff1f               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : lithium148 <\/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>const countResult = await db.collection(&#8216;todos&#8217;).count() const total = countResult.total console.log(total) \/\/total \u4e3a 6<\/p>\n<pre><code>const total = await db.collection('todos').count().total console.log(total) \/\/total \u4e3a null <\/code><\/pre>\n<p>\u8c22\u8c22\uff01<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>5<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"3196356\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Vegetable <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u8bd5\u8bd5\u52a0\u4e86\u62ec\u53f7\u7684\u3002<br \/>const total = (await db.collection(&#8216;todos&#8217;).count()).total<\/p>\n<p>\u53ef\u4ee5\u7406\u89e3\u4e3a\uff0cawait \u751f\u6548\u7684\u90a3\u6b21\u8c03\u7528\uff0c\u662f\u6700\u540e\u4e00\u4e2a\u70b9                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3196357\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : fuzhuo233 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             await \u7684\u4f18\u5148\u7ea7\u5e94\u8be5\u4f4e\u4e8e\u53d6 total \u7684\u503c\uff0c\u800c\u9700\u8981 await \u5148 resolve Promise\uff0c\u624d\u80fd\u5f97\u5230\u7ed3\u679c\u3002\u8bdd\u8bf4\u4f18\u96c5\u4e00\u70b9\u6807\u51c6\u5e26\u8bed\u6cd5\u7cd6\u4e0d\u662f\u7528 const {total} = await db.collection(&#8216;todos&#8217;)                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3196358\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : keepeye <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             await \u53f3\u8fb9\u8868\u8fbe\u5f0f\u7684\u7ed3\u679c <br \/>.count() \u672c\u8eab\u662f\u5f02\u6b65\u7684\uff0c\u8981\u7b49 await \u6210\u529f\u4e4b\u540e\u624d\u80fd\u83b7\u53d6\u5230 total                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3196359\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : keepeye <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             count().total \u662f\u9519\u7684 count()\u662f\u4e2a Promise \u5bf9\u8c61                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3196360\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : azh7138m <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             (await db.collection(&#8216;todos&#8217;).count()).total<\/p>\n<p>await db.collection(&#8216;todos&#8217;).count().total \u5b9e\u9645\u662f await undefined                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>\u8bf7\u95ee\u8fd9\u4e00\u6b65\u4e3a\u5565\u8981\u5206 2 \u6b21\u5199\uff1f \u8cc7&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\/152552"}],"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=152552"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/152552\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=152552"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=152552"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=152552"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}