{"id":939,"date":"2020-02-25T23:40:29","date_gmt":"2020-02-25T15:40:29","guid":{"rendered":"https:\/\/www.bluesdream.com\/blog\/?p=939"},"modified":"2020-03-05T17:36:04","modified_gmt":"2020-03-05T09:36:04","slug":"macos-brew-install-mongodb","status":"publish","type":"post","link":"https:\/\/www.bluesdream.com\/blog\/macos-brew-install-mongodb.html","title":{"rendered":"MacOS \u4f7f\u7528 brew \u5b89\u88c5 MongoDB"},"content":{"rendered":"<h2>\u7b80\u4ecb\uff1a<\/h2>\n<p>MongoDB \u662f\u4e00\u79cd\u9762\u5411\u6587\u6863\u7684\u6570\u636e\u5e93\u7ba1\u7406\u7cfb\u7edf\uff0c\u7528C++\u7b49\u8bed\u8a00\u64b0\u5199\u800c\u6210\u3002\u662f\u4e00\u4e2a\u4ecb\u4e8e\u5173\u7cfb\u6570\u636e\u5e93\u548c\u975e\u5173\u7cfb\u6570\u636e\u5e93\u4e4b\u95f4\u7684\u4ea7\u54c1\uff0c\u9002\u7528\u4e8e\u654f\u6377\u5f00\u53d1\u7684\u6570\u636e\u5e93\u3002<\/p>\n<p><strong>\u4e0e\u5173\u7cfb\u578b\u6570\u636e\u5e93\u5bf9\u6bd4\uff1a<\/strong><\/p>\n<ul>\n<li>\u6570\u636e\u5e93(Database) => \u6570\u636e\u5e93(Database)<\/li>\n<li>\u96c6\u5408(Collection) => \u6570\u636e\u8868(Table)<\/li>\n<li>\u6587\u6863(Document) => \u8bb0\u5f55(Record)<\/li>\n<\/ul>\n<blockquote><p>\n  \u4e3b\u8981\u533a\u522b\uff1a\u6570\u636e\u7ed3\u6784\u8f83\u4e3a\u677e\u6563\uff0c\u7c7b\u4f3c  JSON \u7684\u5b58\u50a8\u683c\u5f0f\uff0c\u6bcf\u6761\u8bb0\u5f55\u7684\u8868\u5b57\u6bb5\u53ef\u4ee5\u4e0d\u540c\u3002\u800c\u5173\u7cfb\u578b\u6570\u636e\u5e93\u6bcf\u4e2a\u8868\u7684\u90fd\u62e5\u6709\u76f8\u540c\u5b57\u6bb5\u3002\n<\/p><\/blockquote>\n<h2>\u5b89\u88c5\uff1a<\/h2>\n<blockquote><p>\n  \u7531\u4e8e MongoDB \u5ba3\u5e03\u4e0d\u518d\u5f00\u6e90\uff0cHomeBrew \u4e5f\u4ece\u6838\u5fc3\u5e93\u4e2d\u79fb\u9664\u4e86 MongoDB \u6a21\u5757 <a href=\"https:\/\/github.com\/Homebrew\/homebrew-core\/pull\/43770\">#43770<\/a>\u3002\u73b0\u5728\u5df2\u65e0\u6cd5\u4f7f\u7528 <code>brew install mongodb<\/code> \u547d\u4ee4\u5b89\u88c5\uff0c\u5426\u5219\u4f1a\u63d0\u793a\u9519\u8bef <code>Error: No available formula with the name \"mongodb\"<\/code>\n<\/p><\/blockquote>\n<p><!--more--><\/p>\n<p>\u6253\u5f00\u7ec8\u7aef\uff0c\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5\uff1a<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n# \u6dfb\u52a0\u7b2c\u4e09\u65b9\u5305\nbrew tap mongodb\/brew\n\n# \u5b89\u88c5\nbrew install mongodb-community\n<\/pre>\n<p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u4f1a\u521b\u5efa\u5982\u4e0b\u6587\u4ef6\uff1a<\/p>\n<ul>\n<li>\u914d\u7f6e\u6587\u4ef6\uff1a<code>\/usr\/local\/etc\/mongod.conf<\/code><\/li>\n<li>\u65e5\u5fd7\u76ee\u5f55\u8def\u5f84\uff1a<code>\/usr\/local\/var\/log\/mongodb<\/code><\/li>\n<li>\u6570\u636e\u76ee\u5f55\u8def\u5f84\uff1a<code>\/usr\/local\/var\/mongodb<\/code><\/li>\n<\/ul>\n<h2>\u521b\u5efa\uff1a<\/h2>\n<p>\u542f\u52a8\u6570\u636e\u5e93\uff1a<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n# \u542f\u52a8\u547d\u4ee4\nbrew services start mongodb-community\n<\/pre>\n<p>\u521b\u5efa\u6570\u636e\u5e93<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n# \u8fdb\u5165\u6570\u636e\u5e93\nmongo\n\n# \u521b\u5efa\u6570\u636e\u5e93\uff08vue_express \u4e3a\u6570\u636e\u5e93\u540d\uff09\nuse vue_express\n<\/pre>\n<blockquote><p>\n  \u6210\u529f\u540e\u663e\u793a\uff1aswitched to db vue_express\n<\/p><\/blockquote>\n<p>\u67e5\u770b\u5f53\u524d\u6570\u636e\u5e93\uff1a<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n# \u6267\u884c\u547d\u540d\ndb\n<\/pre>\n<blockquote><p>\n  \u6210\u529f\u540e\u663e\u793a\uff1avue_express\n<\/p><\/blockquote>\n<p>\u4f46\u6b64\u65f6\u901a\u8fc7 <code>show dbs<\/code> \u547d\u4ee4\u67e5\u770b\u6240\u6709\u6570\u636e\u5e93\u7684\u5217\u8868\uff0c\u5219\u4e0d\u4f1a\u663e\u793a\u521a\u624d\u521b\u5efa\u7684\uff0c\u9700\u8981\u65b0\u589e\u4e00\u6761\u6570\u636e\uff1a<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\ndb.vue_express.insert({&quot;name&quot;:&quot;Hello Word&quot;})\n<\/pre>\n<blockquote><p>\n  \u6210\u529f\u540e\u663e\u793a\uff1aWriteResult({ \"nInserted\" : 1 })\n<\/p><\/blockquote>\n<p>\u521b\u5efa\u7ba1\u7406\u5458\uff1a<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n# \u5207\u6362\u5230\u8d85\u7ea7\u7ba1\u7406\u6a21\u5f0f\nuse admin\n<\/pre>\n<blockquote><p>\n  \u6210\u529f\u540e\u663e\u793a\uff1aswitched to db admin\n<\/p><\/blockquote>\n<p>\u521b\u5efa\u8d85\u7ea7\u7ba1\u7406\u5458\uff1a<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n# \u7528\u6237\u540d\u3001\u5bc6\u7801\u3001\u6743\u9650\ndb.createUser({user:&#039;ryan&#039;, pwd:&#039;123456&#039;, roles:&#x5B;&#039;userAdminAnyDatabase&#039;]})\n<\/pre>\n<blockquote><p>\n  \u6210\u529f\u540e\u663e\u793a\uff1aSuccessfully added user: { \"user\" : \"ryan\", \"roles\" : [ \"userAdminAnyDatabase\" ] }\n<\/p><\/blockquote>\n<ul>\n<li>readAnyDatabase \u4efb\u4f55\u6570\u636e\u5e93\u7684\u53ea\u8bfb\u6743\u9650(\u548cread\u76f8\u4f3c)<\/li>\n<li>readWriteAnyDatabase \u4efb\u4f55\u6570\u636e\u5e93\u7684\u8bfb\u5199\u6743\u9650(\u548creadWrite\u76f8\u4f3c)<\/li>\n<li>userAdminAnyDatabase \u4efb\u4f55\u6570\u636e\u5e93\u7528\u6237\u7684\u7ba1\u7406\u6743\u9650(\u548cuserAdmin\u76f8\u4f3c)<\/li>\n<li>dbAdminAnyDatabase \u4efb\u4f55\u6570\u636e\u5e93\u7684\u7ba1\u7406\u6743\u9650(dbAdmin\u76f8\u4f3c)<\/li>\n<\/ul>\n<h2>\u57fa\u672c\u64cd\u4f5c\uff1a<\/h2>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n# \u542f\u52a8\u547d\u4ee4\nbrew services start mongodb-community\n\n# \u505c\u6b62\u547d\u4ee4\nbrew services stop mongodb-community\n\n# \u91cd\u542f\u547d\u4ee4\nbrew services restart mongodb-community\n\n# \u8fdb\u5165 mango\nmonngo\n\n# \u663e\u793a\u6570\u636e\u5e93\u5217\u8868\nshow dbs\n\n# \u521b\u5efa\/\u5207\u6362\u6570\u636e\u5e93\nuse &lt;collection_name&gt;\n\n# \u521b\u5efa\u96c6\u5408\uff08\u6570\u636e\u8868\u5355\uff09\ndb.createCollection(&quot;Posts&quot;)\n\n# \u67e5\u770b\u5f53\u524d\u6570\u636e\u5e93\u96c6\u5408\nshow collections\n\n# \u663e\u793a\u5f53\u524d\u6570\u636e\u5e93\u72b6\u6001\ndb.stats()\n\n# \u5220\u5f53\u524d\u4f7f\u7528\u7684\u6570\u636e\u5e93\ndb.dropDatabase()\n\n# \u4fee\u590d\u5f53\u524d\u6570\u636e\u5e93\ndb.repairDatabase()\n\n# \u663e\u793a\u5f53\u524d\u6570\u636e\u5e93\u7248\u672c\ndb.version\n\n# \u96c6\u5408\u6587\u6863\u63d2\u5165\ndb.&lt;collection_name&gt;.insert()\n\n# \u67e5\u8be2\u96c6\u5408\u4e2d\u6587\u6863\u603b\u6570\ndb.&lt;collection_name&gt;.count()\n\n# \u67e5\u8be2\u96c6\u5408\u5185\u6240\u6709\u6587\u6863\ndb.&lt;collection_name&gt;.find()\n\n# \u96c6\u5408\u6587\u6863\u7684\u6761\u4ef6\u67e5\u8be2\n# \u5927\u4e8e\u7b49\u4e8e\uff1a$gte | \u5927\u4e8e\uff1a$gt | \u5c0f\u4e8e\u7b49\u4e8e\uff1a$lte | \u5c0f\u4e8e\uff1a$lt | \u7b49\u4e8e\uff1a$eq | \u4e0d\u7b49\u4e8e\uff1a$ne\n# \u5b58\u5728\u67d0\u4e2a\u5b57\u6bb5\u65f6\u624d\u62bd\u51fa\uff1a$exists\ndb.&lt;collection_name&gt;.find({&quot;title&quot;: {$exists:true}})\n\n# \u62bd\u51fa\u96c6\u5408\u6587\u6863\u5185\u6307\u5b9a\u5b57\u6bb5\u7684\u6570\u636e\uff08\u5176\u4f59\u5b57\u6bb5\u4e0d\u663e\u793a\uff09\ndb.&lt;collection_name&gt;.find({}\uff0c{title:true, date:true}})\n\n# \u62bd\u51fa\u6587\u6863\u7684\u65b9\u6cd5\n# \u5012\u53d9\uff1asort() | \u9650\u5236\uff1alimit() | \u8df3\u8fc7\uff1askip()\ndb.&lt;collection_name&gt;.find({}\uff0c{_id:0}).limit(5)\n\n# \u67e5\u8be2\u96c6\u5408\u5185\u6307\u5b9a\u6570\u636e\ndb.&lt;collection_name&gt;.findById()\n\n# \u96c6\u5408\u6587\u6863\u66f4\u65b0\uff08\u7b26\u5408\u6761\u4ef6\u7684\u7b2c\u4e00\u6761\u8bb0\u5f55\uff09\n# update(&lt;filter&gt;, &lt;update&gt;, (options))\ndb.&lt;collection_name&gt;.update({&quot;tag&quot;:&quot;\u53e3\u7f69&quot;}, {$set: {&quot;unit&quot;:10}})\n\n# \u96c6\u5408\u6587\u6863\u66f4\u65b0\uff08\u7b26\u5408\u6761\u4ef6\u7684\u6240\u6709\u8bb0\u5f55\uff09\ndb.&lt;collection_name&gt;.update({&quot;tag&quot;:&quot;\u53e3\u7f69&quot;}, {$set: {&quot;unit&quot;:10}}, {multi:true})\n\n# \u96c6\u5408\u6587\u6863\u4fee\u6539\uff08\u7279\u6b8a\u51fd\u6570\uff0c\u539f&quot;unit&quot;\u57fa\u7840\u4e0a\u589e\u52a05\uff09\n# \u9012\u52a0\uff1a$inc | \u76f8\u4e58\uff1a$mul | \u6539\u540d\uff1a$rename | \u65b0\u589e\/\u4fee\u6539\uff1a$set | \u5220\u9664\u5b57\u6bb5\uff1a$unset\ndb.&lt;collection_name&gt;.update({&quot;title&quot;:&quot;N95&quot;}, {$inc: {unit: 5}})\n\n# \u96c6\u5408\u6587\u6863\u7684\u7279\u6b8a\u66f4\u65b0\uff08\u6709\u8bb0\u5f55\u5c31\u66f4\u65b0\uff0c\u65e0\u8bb0\u5f55\u5c31\u4f60\u8ffd\u52a0\uff09\ndb.&lt;collection_name&gt;.update({&quot;title&quot;:&quot;N90&quot;}, {&quot;title&quot;:&quot;N90&quot;, &quot;tag&quot;:&quot;\u53e3\u7f69&quot;, &quot;unit&quot;:10}, {upsert:true})\n\n# \u96c6\u5408\u6587\u6863\u66f4\u65b0\uff08\u5355\u6761\u8bb0\u5f55\uff09\ndb.&lt;collection_name&gt;.updateOne()\n\n# \u53ea\u5220\u9664\u6587\u6863\u5185\u7b2c\u4e00\u4e2a\u5339\u914d\u7684\ndb.&lt;collection_name&gt;.deleteOne()\n\n# \u5220\u9664\u6587\u6863\u5185\u6240\u6709\u5339\u914d\u7684\ndb.&lt;collection_name&gt;.deleteMany()\n\n# \u5220\u9664\u96c6\u5408\u4e2d\u6240\u6709\u6587\u6863\ndb.&lt;collection_name&gt;.remove()\n<\/pre>\n<h2>\u53c2\u8003\u8d44\u6599\uff1a<\/h2>\n<p><a href=\"https:\/\/docs.mongodb.com\/manual\/\">The MongoDB 4.2 Manual<\/a><br \/>\n<a href=\"https:\/\/www.w3cschool.cn\/mongodb\/\">MongoDB \u6559\u7a0b<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7b80\u4ecb\uff1a MongoDB \u662f\u4e00\u79cd\u9762\u5411\u6587\u6863\u7684\u6570\u636e\u5e93\u7ba1\u7406\u7cfb\u7edf\uff0c\u7528C++\u7b49\u8bed\u8a00\u64b0\u5199\u800c\u6210\u3002\u662f\u4e00\u4e2a\u4ecb\u4e8e\u5173\u7cfb\u6570\u636e\u5e93\u548c\u975e\u5173\u7cfb\u6570\u636e\u5e93\u4e4b\u95f4\u7684\u4ea7\u54c1\uff0c\u9002\u7528\u4e8e\u654f\u6377\u5f00\u53d1\u7684\u6570\u636e\u5e93\u3002 \u4e0e\u5173\u7cfb\u578b\u6570\u636e\u5e93\u5bf9\u6bd4\uff1a \u6570\u636e\u5e93(Database) => \u6570\u636e\u5e93(Database) \u96c6\u5408(Collection) => \u6570\u636e\u8868(Table) \u6587\u6863(Document) => \u8bb0\u5f55(Record) \u4e3b\u8981\u533a\u522b\uff1a\u6570\u636e\u7ed3\u6784\u8f83\u4e3a\u677e\u6563\uff0c\u7c7b\u4f3c JSON \u7684\u5b58\u50a8\u683c\u5f0f\uff0c\u6bcf\u6761\u8bb0\u5f55\u7684\u8868\u5b57\u6bb5\u53ef\u4ee5\u4e0d\u540c\u3002\u800c\u5173\u7cfb\u578b\u6570\u636e\u5e93\u6bcf\u4e2a\u8868\u7684\u90fd\u62e5\u6709\u76f8\u540c\u5b57\u6bb5\u3002 \u5b89\u88c5\uff1a \u7531\u4e8e MongoDB \u5ba3\u5e03\u4e0d\u518d\u5f00\u6e90\uff0cHomeBrew \u4e5f\u4ece\u6838\u5fc3\u5e93\u4e2d\u79fb\u9664\u4e86 MongoDB \u6a21\u5757 #43770\u3002\u73b0\u5728\u5df2\u65e0\u6cd5\u4f7f\u7528 brew install mongodb \u547d\u4ee4\u5b89\u88c5\uff0c\u5426\u5219\u4f1a\u63d0\u793a\u9519\u8bef Error: No available formula with the name \"mongodb\"<\/p>\n","protected":false},"author":1,"featured_media":941,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[75],"tags":[187,185,186],"class_list":["post-939","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-front-end","tag-brew","tag-macos","tag-mongodb"],"_links":{"self":[{"href":"https:\/\/www.bluesdream.com\/blog\/wp-json\/wp\/v2\/posts\/939"}],"collection":[{"href":"https:\/\/www.bluesdream.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bluesdream.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bluesdream.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bluesdream.com\/blog\/wp-json\/wp\/v2\/comments?post=939"}],"version-history":[{"count":0,"href":"https:\/\/www.bluesdream.com\/blog\/wp-json\/wp\/v2\/posts\/939\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.bluesdream.com\/blog\/wp-json\/wp\/v2\/media\/941"}],"wp:attachment":[{"href":"https:\/\/www.bluesdream.com\/blog\/wp-json\/wp\/v2\/media?parent=939"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bluesdream.com\/blog\/wp-json\/wp\/v2\/categories?post=939"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bluesdream.com\/blog\/wp-json\/wp\/v2\/tags?post=939"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}