{"id":3461,"date":"2020-03-31T15:11:03","date_gmt":"2020-03-31T07:11:03","guid":{"rendered":"https:\/\/www.webteach.tw\/?p=3461"},"modified":"2020-03-31T15:11:03","modified_gmt":"2020-03-31T07:11:03","slug":"show-collections","status":"publish","type":"post","link":"https:\/\/www.webteach.tw\/?p=3461","title":{"rendered":"[ MongoDB ] &#8211; How to show collections in PHP7"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">MongoDB \u771f\u662f\u8b93\u4eba\u53c8\u611b\u53c8\u6068\uff0c\u8cc7\u6599json\u5316\u5df2\u7d93\u662f\u5927\u52e2\u6240\u8da8\uff0c\u50b3\u7d71\u95dc\u806f\u5f0f\u8cc7\u6599\u5eab\u96d6\u7136\u5df2\u9032\u5316\u5230\u53ef\u4ee5\u5b58json\u683c\u5f0f\u4f46\u7d71\u8a08\u65b9\u9762\u9084\u662f\u4e0d\u4fbf\uff0c\u9019\u6b21\u8981\u505a\u5230\u7684\u529f\u80fd\u5176\u5be6\u5f88\u7c21\u55ae\u5c31\u662f show collections \uff0c\u5217\u51fa\u6240\u6709\u96c6\u5408(\u8cc7\u6599\u8868)\uff0c\u4e0b\u6307\u4ee4\u5f88\u7c21\u55ae \u4f46 php \u65b0\u7248\u7684mongodb \u9a45\u52d5\u5df2\u66f4\u65b0\uff0c\u820a\u7684\u8a9e\u6cd5\u4e0d\u80fd\u7528\u8457\u5be6\u8b93\u6211\u5f88\u56f0\u64fe\u3002<\/p>\n\n\n<p class=\"wp-block-paragraph\">\u672c\u4f86\u6709\u627e\u5230\u4e00\u500b php mongodb library \u4f46\u7248\u672c\u4e00\u76f4\u5c0d\u4e0d\u4e0a\uff0c\u53ea\u597d\u653e\u68c4\u4f46\u597d\u5728\u8a72\u5c08\u6848\u6709\u4e0agithub\u6240\u4ee5\u5c31\u53bb\u722c\u4ed6\u7684code\u7e3d\u7b97\u627e\u5230\u6211\u6240\u9700\u8981\u7684\u6307\u4ee4 listCollections\uff0c\u4ee5\u4e0b\u76f4\u63a5\u4e0acode<\/p>\n\n\n<pre class=\"wp-block-code\"><code>$manager = new MongoDB\\Driver\\Manager(\"mongodb:\/\/\u5e33\u865f:\u5bc6\u78bc@\u4e3b\u6a5fip:27017\/\u8cc7\u6599\u5eab\");\ncmd = new MongoDB\\Driver\\Command(&#91;\n\t 'listCollections' => 1,\n\t 'cursor' => new stdClass,\n]);\n$cursor = $manager->executeCommand('\u8cc7\u6599\u5eab', $cmd);\n$collections_ar=array();\nforeach ($cursor as $document) {\n\tarray_push($collections_ar,$document->name);\/\/\u96c6\u5408\u540d\u7a31\u5b58\u6210\u9663\u5217\n}\nrsort($collections_ar);\/\/\u6211\u7684\u9700\u6c42\u662f \u5927\u5230\u5c0f\u6392\u5e8f\nprint_r($collections_ar);<\/code><\/pre>\n\n\n<p class=\"wp-block-paragraph\">\u986f\u793a\u7d50\u679c <br \/>\nArray ( [0] =&gt; log_2020_03_31 [1] =&gt; log_2020_03_30 [2] =&gt; log_2020_03_27 [3] =&gt; log_2020_03_26 [4] =&gt; log_2020_03_25 [5] =&gt; log_2020_03_24 [6] =&gt; log_2020_03_23 [7] =&gt; log_2020_03_22 [8] =&gt; log_2020_03_21 [9] =&gt; log_2020_03_20 [10] =&gt; log_2020_03_19 [11] =&gt; log_2020_03_18 [12] =&gt; log_2020_03_17 [13] =&gt; log_2020_03_16 [14] =&gt; log_2020_03_15 [15] =&gt; log_2020_03_14 [16] =&gt; log_2020_03_13 [17] =&gt; log_2020_03_12 [18] =&gt; log_2020_03_11 [19] =&gt; log_2020_03_10 [20] =&gt; log_2020_03_09 [21] =&gt; log_2020_03_08 [22] =&gt; log_2020_03_07 [23] =&gt; log_2020_03_06 [24] =&gt; log_2020_03_05 [25] =&gt; log_2020_03_04 [26] =&gt; log_2020_03_03 [27] =&gt; log_2020_03_02 [28] =&gt; log_2020_03_01 )<\/p>\n\n\n<p class=\"wp-block-paragraph\">\u53c3\u8003\u9023\u7d50\uff1a<a href=\"https:\/\/github.com\/mongodb\/mongo-php-library\/blob\/master\/src\/Operation\/ListCollections.php\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\" (\u5728\u65b0\u5206\u9801\u4e2d\u958b\u555f)\">https:\/\/github.com\/mongodb\/mongo-php-library\/blob\/master\/src\/Operation\/ListCollections.php<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\t\t\t\t\u7136\u5df2\u9032\u5316\u5230\u53ef\u4ee5\u5b58json\u683c\u5f0f\u4f46\u7d71\u8a08\u65b9\u9762\u9084\u662f\u4e0d\u4fbf\uff0c\u9019\u6b21\u8981\u505a\u5230\u7684\u529f\u80fd\u5176\u5be6\u5f88\u7c21\u55ae\u5c31\u662f show collections \uff0c\u5217\u51fa\u6240\u6709\u96c6\u5408(\u8cc7\u6599\u8868)\uff0c\u4e0b\u6307\u4ee4\u5f88\u7c21\u55ae \u4f46 php \u65b0\u7248\u7684mongodb \u9a45\u52d5\u5df2\u66f4\u65b0\uff0c\u820a\u7684\u8a9e\u6cd5\u4e0d\u80fd\u7528\u8457\u5be6\u8b93\u6211\u5f88\u56f0\u64fe\u3002\t\t<\/p>\n","protected":false},"author":1,"featured_media":3825,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[33],"tags":[395,448,514],"class_list":["post-3461","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-mongodb","tag-mongodb","tag-php","tag-show-collections","hvn-theme-has-thumbnail"],"_links":{"self":[{"href":"https:\/\/www.webteach.tw\/index.php?rest_route=\/wp\/v2\/posts\/3461","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.webteach.tw\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.webteach.tw\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.webteach.tw\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.webteach.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3461"}],"version-history":[{"count":0,"href":"https:\/\/www.webteach.tw\/index.php?rest_route=\/wp\/v2\/posts\/3461\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.webteach.tw\/index.php?rest_route=\/wp\/v2\/media\/3825"}],"wp:attachment":[{"href":"https:\/\/www.webteach.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3461"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.webteach.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3461"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.webteach.tw\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3461"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}