成人国产在线小视频_日韩寡妇人妻调教在线播放_色成人www永久在线观看_2018国产精品久久_亚洲欧美高清在线30p_亚洲少妇综合一区_黄色在线播放国产_亚洲另类技巧小说校园_国产主播xx日韩_a级毛片在线免费

資訊專欄INFORMATION COLUMN

mac下mongodb的安裝與配置

molyzzx / 3377人閱讀

本文相關(guān)源碼

安裝 mongodb

install 之前,iTerm2 下用 brew 查看已安裝軟件、搜索 mongodb:

brew list
brew search mongodb

安裝 mongodb :

brew install mongodb

此處需要稍等一段時(shí)間,成功后會(huì)輸出以下即說(shuō)明安裝成功:

$ brew install mongodb
Updating Homebrew...
==> Downloading https://homebrew.bintray.com/bottles/mongodb-3.4.0.sierra.bottle.1.tar.gz
######################################################################## 100.0%
==> Pouring mongodb-3.4.0.sierra.bottle.1.tar.gz
==> Caveats
To have launchd start mongodb now and restart at login:
  brew services start mongodb
Or, if you don"t want/need a background service you can just run:
  mongod --config /usr/local/etc/mongod.conf
==> Summary
?  /usr/local/Cellar/mongodb/3.4.0: 17 files, 261.4M
啟動(dòng) mongodb

新建一個(gè) iTerm2 窗口,執(zhí)行 mongod 嘗試啟動(dòng) mongodb 但會(huì)失敗 exiting:

$ mongod
2017-06-12T15:51:49.810+0800 I CONTROL  [initandlisten] MongoDB starting : pid=1765 port=27017 dbpath=/data/db 64-bit host=MacBook-Pro-2.local
2017-06-12T15:51:49.810+0800 I CONTROL  [initandlisten] db version v3.4.0
2017-06-12T15:51:49.810+0800 I CONTROL  [initandlisten] git version: f4240c60f005be757399042dc12f6addbc3170c1
2017-06-12T15:51:49.810+0800 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.0.2j  26 Sep 2016
2017-06-12T15:51:49.810+0800 I CONTROL  [initandlisten] allocator: system
2017-06-12T15:51:49.810+0800 I CONTROL  [initandlisten] modules: none
2017-06-12T15:51:49.810+0800 I CONTROL  [initandlisten] build environment:
2017-06-12T15:51:49.810+0800 I CONTROL  [initandlisten]     distarch: x86_64
2017-06-12T15:51:49.810+0800 I CONTROL  [initandlisten]     target_arch: x86_64
2017-06-12T15:51:49.810+0800 I CONTROL  [initandlisten] options: {}
2017-06-12T15:51:49.811+0800 I STORAGE  [initandlisten] exception in initAndListen: 29 Data directory /data/db not found., terminating
2017-06-12T15:51:49.811+0800 I NETWORK  [initandlisten] shutdown: going to close listening sockets...
2017-06-12T15:51:49.811+0800 I NETWORK  [initandlisten] shutdown: going to flush diaglog...
2017-06-12T15:51:49.811+0800 I CONTROL  [initandlisten] now exiting
2017-06-12T15:51:49.811+0800 I CONTROL  [initandlisten] shutting down with code:100

啟動(dòng) mongodb 之前,要先新建一個(gè)mongodb默認(rèn)的數(shù)據(jù)寫(xiě)入目錄:

$ mkdir -p /data/db
mkdir: /data/db: Permission denied (沒(méi)有權(quán)限拒絕訪問(wèn))

// sudo 并輸入密碼,重新新建目錄
$ sudo mkdir -p /data/db
Password:

給剛才新建的數(shù)據(jù)庫(kù)目錄賦予權(quán)限:

$ sudo chown -R guojc /data

此時(shí),執(zhí)行 mongod 啟動(dòng) mongodb 服務(wù):

$ mongod
2017-06-12T16:00:48.036+0800 I CONTROL  [initandlisten] MongoDB starting : pid=1837 port=27017 dbpath=/data/db 64-bit host=MacBook-Pro-2.local
2017-06-12T16:00:48.037+0800 I CONTROL  [initandlisten] db version v3.4.0
2017-06-12T16:00:48.037+0800 I CONTROL  [initandlisten] git version: f4240c60f005be757399042dc12f6addbc3170c1
2017-06-12T16:00:48.037+0800 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.0.2j  26 Sep 2016
2017-06-12T16:00:48.037+0800 I CONTROL  [initandlisten] allocator: system
2017-06-12T16:00:48.037+0800 I CONTROL  [initandlisten] modules: none
2017-06-12T16:00:48.037+0800 I CONTROL  [initandlisten] build environment:
2017-06-12T16:00:48.037+0800 I CONTROL  [initandlisten]     distarch: x86_64
2017-06-12T16:00:48.037+0800 I CONTROL  [initandlisten]     target_arch: x86_64
2017-06-12T16:00:48.037+0800 I CONTROL  [initandlisten] options: {}
2017-06-12T16:00:48.037+0800 I STORAGE  [initandlisten] wiredtiger_open config: create,cache_size=3584M,session_max=20000,eviction=(threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),checkpoint=(wait=60,log_size=2GB),statistics_log=(wait=0),
2017-06-12T16:00:48.616+0800 I CONTROL  [initandlisten]
2017-06-12T16:00:48.616+0800 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2017-06-12T16:00:48.616+0800 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2017-06-12T16:00:48.616+0800 I CONTROL  [initandlisten]
2017-06-12T16:00:48.665+0800 I FTDC     [initandlisten] Initializing full-time diagnostic data capture with directory "/data/db/diagnostic.data"
2017-06-12T16:00:48.741+0800 I INDEX    [initandlisten] build index on: admin.system.version properties: { v: 2, key: { version: 1 }, name: "incompatible_with_version_32", ns: "admin.system.version" }
2017-06-12T16:00:48.741+0800 I INDEX    [initandlisten]    building index using bulk method; build may temporarily use up to 500 megabytes of RAM
2017-06-12T16:00:48.755+0800 I INDEX    [initandlisten] build index done.  scanned 0 total records. 0 secs
2017-06-12T16:00:48.756+0800 I COMMAND  [initandlisten] setting featureCompatibilityVersion to 3.4
2017-06-12T16:00:48.756+0800 I NETWORK  [thread1] waiting for connections on port 27017

mongodb 啟動(dòng)成功,正等待著被連接。

新建 iTerm2 窗口,執(zhí)行 mongo,進(jìn)入 mongodb 命令行模式:

$ mongo
MongoDB shell version v3.4.0
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.4.0
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
  http://docs.mongodb.org/
Questions? Try the support group
  http://groups.google.com/group/mongodb-user
Server has startup warnings:
2017-06-12T16:00:48.616+0800 I CONTROL  [initandlisten]
2017-06-12T16:00:48.616+0800 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2017-06-12T16:00:48.616+0800 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2017-06-12T16:00:48.616+0800 I CONTROL  [initandlisten]
>

繼續(xù)在上面的終端輸入 show dbs,會(huì)列出系統(tǒng)自帶的2個(gè)數(shù)據(jù)庫(kù):

> show dbs
admin  0.000GB
local  0.000GB
help

小結(jié)一下,往后要重新啟動(dòng) mongodb 服務(wù)、進(jìn)入 mongodb 命令行的操作:
在一個(gè)iTerm2窗口執(zhí)行:mongod //MongoDB starting........waiting for connections
另一個(gè)iTerm2窗口執(zhí)行:mongo //MongoDB shell

插入數(shù)據(jù)

首先,在電腦根目錄下安裝 node 的數(shù)據(jù)驅(qū)動(dòng)庫(kù):

# guojc @ MacBook-Pro-2 in ~ [16:29:33] C:127
$ cnpm install mongodb

新建目錄并編輯text.js文件: s3_mongodb/test.js:

var MongoClient = require("mongodb").MongoClient;
// 連接數(shù)據(jù)庫(kù)
var url_test = "mongodb://localhost:27017/test"; //數(shù)據(jù)庫(kù)test本不存在,連接時(shí)會(huì)自動(dòng)創(chuàng)建

var insertData = function(db){
  // 往test數(shù)據(jù)庫(kù)里新建一個(gè)site集合,并插入一條數(shù)據(jù)
  db.collection("site").insertOne({name: "guojc", age: 99, hobby: "movie"}, function(err, result){
    console.log("inserted successly");
    console.log(result);
    db.close();
    console.log("close");
  });
}

MongoClient.connect(url_test, function(err, db) {
  console.log("Connected successly to server.");
  insertData(db);
});

新建 iTerm2 窗口,運(yùn)行 test.js:

node test.js

成功后,來(lái)到之前執(zhí)行過(guò) mongo 的 MongoDB shell 窗口,執(zhí)行:

> show dbs
admin  0.000GB
local  0.000GB
test  0.000GB
help

繼續(xù)執(zhí)行:選中數(shù)據(jù)庫(kù)test、顯示test中的表,查詢?cè)摫淼乃袛?shù)據(jù):

> use test
switched to db test

> show tables
site

> db.site.find()
{ "_id" : ObjectId("593e594ab4727b09349c33a6"), "name" : "guojc", "age" : 99, "hobby" : "movie" }

至此,mongodb的安裝配置與基本啟動(dòng)就介紹完了。
下一篇繼續(xù)學(xué)習(xí)使用 mongoose 來(lái)操作 mongodb 。

文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉(zhuǎn)載請(qǐng)注明本文地址:http://systransis.cn/yun/19045.html

相關(guān)文章

  • MongoDB安裝啟動(dòng)(Mac 版)

    摘要:本次講述安裝的當(dāng)然是免費(fèi)的社區(qū)版。兩種安裝方法手動(dòng)安裝,需要下載安裝包解壓編譯比較繁瑣使用系統(tǒng)的安裝,是系統(tǒng)上的包管理工具,類似的。如文章出現(xiàn)有錯(cuò)誤,麻煩指出或有相關(guān)知識(shí)點(diǎn)討論也十分歡迎 Mac上裝MongoDB的官網(wǎng)教程:https://docs.mongodb.com/manu...,英文不錯(cuò)的可以直接看,教程也很清晰。 兩種版本 MongoDB有兩種版本: 1.(Enterpri...

    keithyau 評(píng)論0 收藏0
  • Mac 環(huán)境安裝配置mongodb并創(chuàng)建用戶

    摘要:環(huán)境下安裝配置并創(chuàng)建用戶好久之前曾經(jīng)安裝過(guò)在一個(gè)偶然的情況下被一個(gè)大佬直接登陸進(jìn)來(lái)了,剛開(kāi)始驚呼還有這種操作,后來(lái)才發(fā)現(xiàn)自己并沒(méi)有給數(shù)據(jù)庫(kù)上鎖,并且在安裝完默認(rèn)啟動(dòng)的時(shí)候默認(rèn)是任何都可以不需要密碼直接訪問(wèn)的。 Mac 環(huán)境下安裝配置mongodb并創(chuàng)建用戶 好久之前曾經(jīng)安裝過(guò)mongodb,在一個(gè)偶然的情況下被一個(gè)大佬直接登陸進(jìn)來(lái)了,剛開(kāi)始驚呼還有這種操作,后來(lái)才發(fā)現(xiàn)自己并沒(méi)有給數(shù)據(jù)庫(kù)...

    livem 評(píng)論0 收藏0
  • 親測(cè)成功在Mac安裝MongoDB(附win安裝教程)

    摘要:安裝目錄下配置系統(tǒng)環(huán)境變量驗(yàn)證是否安裝成功,打開(kāi),鍵入命令,能看到版本號(hào)即安裝成功。 showImg(https://segmentfault.com/img/bVEHkW?w=269&h=108); MongoDB是一個(gè)基于分布式文件存儲(chǔ)的數(shù)據(jù)庫(kù),由C++語(yǔ)言編寫(xiě),旨在為WEB應(yīng)用提供可擴(kuò)展的高性能數(shù)據(jù)存儲(chǔ)解決方案。MongoDB是一個(gè)介于關(guān)系數(shù)據(jù)庫(kù)和非關(guān)系數(shù)據(jù)庫(kù)之間的產(chǎn)品,是非關(guān)系...

    happyfish 評(píng)論0 收藏0
  • 親測(cè)成功在Mac安裝MongoDB(附win安裝教程)

    摘要:安裝目錄下配置系統(tǒng)環(huán)境變量驗(yàn)證是否安裝成功,打開(kāi),鍵入命令,能看到版本號(hào)即安裝成功。 showImg(https://segmentfault.com/img/bVEHkW?w=269&h=108); MongoDB是一個(gè)基于分布式文件存儲(chǔ)的數(shù)據(jù)庫(kù),由C++語(yǔ)言編寫(xiě),旨在為WEB應(yīng)用提供可擴(kuò)展的高性能數(shù)據(jù)存儲(chǔ)解決方案。MongoDB是一個(gè)介于關(guān)系數(shù)據(jù)庫(kù)和非關(guān)系數(shù)據(jù)庫(kù)之間的產(chǎn)品,是非關(guān)系...

    Code4App 評(píng)論0 收藏0
  • Tornado 簡(jiǎn)單入門(mén)教程(零)——準(zhǔn)備工作

    摘要:學(xué)的過(guò)程中查閱了無(wú)數(shù)資料,也收獲了一些經(jīng)驗(yàn),所以希望總結(jié)出一份簡(jiǎn)易入門(mén)教程供初學(xué)者參考。完整的教程將盡可能遵循下面的目錄順序。安裝的安裝也很簡(jiǎn)單。搭建簡(jiǎn)單服務(wù)器表示不是必要的這里僅以做示范,其他系統(tǒng)操作方法類似。 前言: 這兩天在學(xué)著用Python + Tornado +MongoDB來(lái)做Web開(kāi)發(fā)(哈哈哈這個(gè)詞好高端)。學(xué)的過(guò)程中查閱了無(wú)數(shù)資料,也收獲了一些經(jīng)驗(yàn),所以希望總結(jié)出一份...

    lifefriend_007 評(píng)論0 收藏0

發(fā)表評(píng)論

0條評(píng)論

閱讀需要支付1元查看
<