{"id":3335,"date":"2019-12-19T12:21:05","date_gmt":"2019-12-19T04:21:05","guid":{"rendered":"https:\/\/www.webteach.tw\/?p=3335"},"modified":"2019-12-19T12:21:05","modified_gmt":"2019-12-19T04:21:05","slug":"mongodb-2","status":"publish","type":"post","link":"https:\/\/www.webteach.tw\/?p=3335","title":{"rendered":"[ MongoDB ] &#8211; MongoDB PHP \u57fa\u790e\u7bc4\u4f8b"},"content":{"rendered":"\n\t\t\t\t\n<p class=\"wp-block-paragraph\">MongoDB PHP \u57fa\u790e\u7bc4\u4f8b<\/p>\n\n\n<pre class=\"wp-block-code\"><code> &lt;?php\n\/\/ \u65b0\u589e\u4e00\u500b\u8cc7\u6599\u5eab\u9023\u7d50\n$m = new Mongo();\n\/\/ \u9078\u64c7\u8cc7\u6599\u5eab\n$db = $m->ttedb;\n\/\/ \u9078\u64c7\u4e00\u500b\u8cc7\u6599\u96c6\u5408 (\u985e\u4f3c\u95dc\u806f\u5f0f\u8cc7\u6599\u5eab\u7684 table)\n$collection = $db->merchant;\n\/\/$querys = array(\"merchantCode\" => new MongoRegex(\"\/TW000000\/$i\"));\n\/\/LIKE \u67e5\u8a62\u4f7f\u7528\u6b63\u898f\u8868\u793a\u5f0f\n\/*$querys = array('$or' => array(\n                               array(\"mCode\" => new MongoRegex(\"\/TW000000\/$i\")),\n                               array('agreementAccepted'=>true)\n                              )\n              );*\/\n\/\/OR \u67e5\u8a62\u7528\u6cd5\n\/\/$querys=array(\"merchantCode\"=>'TW0000019');\n\/\/\u57fa\u672c\u55ae\u4e00\u689d\u4ef6\n\/*$collection->update(\n                    array(\"mCode\"=>'TW10000019'),\n                    array('$set'=>array(\"name\"=>\"Mon\"))\n                    );\n\/\/\u66f4\u65b0\u67d0\u500b\u6b04\u4f4d\u7684\u8cc7\u6599\n\/*$data = array( \"class\"=>\"123\",\"email\" => \"jeff@dd.com.tw\" );\n$collection->insert($data);*\/\n\/\/\u65b0\u589e\u4e00\u7b46\u8cc7\u6599\n\/\/echo $collection->count();\n\/\/\u986f\u793a\u8cc7\u6599\u7e3d\u7b46\u6578\n\/\/$collection->remove(array(\"email\"=>\"jeff@dd.com.tw\"));\n\/\/\u522a\u9664\u4e00\u7b46\u8cc7\u6599\n\/\/$cursor=$collection->find($querys);\n\/*foreach ($cursor as $obj) {\n    echo 'id:'.$obj[\"_id\"] . \"&lt;br\/>\";\n    echo 'email:'.$obj[\"email\"] . \"&lt;br\/>\";\n    echo 'mCode:'.$obj[\"mCode\"] . \"&lt;br\/>\";\n    echo 'name:'.$obj[\"name\"].\"&lt;br\/>&lt;br\/>\";\n} *\/\n\/\/\u900f\u51fa\u9663\u5217\u8cc7\u6599\n?>\n\u4ee5\u4e0a\u7bc4\u4f8b\u8acb\u81ea\u884c\u66f4\u6539\u8cc7\u6599\u5eab\u76f8\u95dc\u9023\u7d50\u8207\u6b04\u4f4d<\/code><\/pre>\n\t\t","protected":false},"excerpt":{"rendered":"<p>\t\t\t\tMongoDB PHP \u57fa\u790e\u7bc4\u4f8b\t\t<\/p>\n","protected":false},"author":1,"featured_media":2201,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[36],"tags":[395,448,1198],"class_list":["post-3335","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-php","tag-mongodb","tag-php","tag-1198","hvn-theme-has-thumbnail"],"_links":{"self":[{"href":"https:\/\/www.webteach.tw\/index.php?rest_route=\/wp\/v2\/posts\/3335","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=3335"}],"version-history":[{"count":0,"href":"https:\/\/www.webteach.tw\/index.php?rest_route=\/wp\/v2\/posts\/3335\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.webteach.tw\/index.php?rest_route=\/wp\/v2\/media\/2201"}],"wp:attachment":[{"href":"https:\/\/www.webteach.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3335"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.webteach.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3335"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.webteach.tw\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3335"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}