mongoDB
安裝
安裝mongoDB 有兩種方法,一種是apt-get安裝,一種是直接下載源碼包安裝
這里介紹源碼包安裝
-
使用wget命令下載源碼包
wget -c https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-ubuntu1604-3.2.8.tgz
-
解壓到當前文件夾并重命名,重命名是為了方便
tar -zxvf mongodb-linux-i686-3.2.8.tgz
mv mongodb-linux-i686-3.2.8 mongodb
啟動
啟動之前需要事先建立一個文件夾來存放數(shù)據(jù)庫,這里就建立一個daihuanqi_db
mkdir /mongodb/daihuanqi_db
然后進入mongodb/bin目錄下 執(zhí)行
./mongod --dbpath=../daihuanqi_db
基本操作
查看所有數(shù)據(jù)庫:
show dbs;
查看集合:
show collections;
插入一條記錄:
db.user.insert({"name":"daihuanqi","phone":"18392322209"});
插入多條記錄:
db.user.insertMany([
{"name":"daihuanqi","phone":"18392322209"},
{"name":"daihuanqi","phone":"18392322209"},
{"name":"daihuanqi","phone":"18392322209"}
]);
注:每條記錄都有一個objectID
查找記錄:
db.user.find();
格式化查詢
db.user.find().pretty;
更新 第一個參數(shù)是條件,后面是修改的內容,第三個參數(shù)是否插入,當沒找到時。第四個參數(shù)是否全部修改符合條件的
db.user.update({"name":"longdage"},{$set:{sex:000}},true
);
刪除
db.user.remove({zhiwu:"av"});
查看當前版本
db.version()
查看集合
db.getCollectionNames();
查看當前數(shù)據(jù)庫
db.getName();
express框架
安裝
npm install -g express-generator
建立項目
express -e project_name
安裝資源包
npm install
注:npm install 有可能無反應,因為可能被墻
解決方法:使用smart-npm
安裝:
npm install --global smart-npm --registry=https://registry.npm.taobao.org/
卸載:
npm smart uninstall # 2.x.x 版本的 smart-npm 在卸載前需要先執(zhí)行此腳本
npm uninstall --global smart-npm
使用:
安裝后系統(tǒng)的 npm 會被替換了,如果你要使用原生的 npm 命令,可以用 npm-original 代替。
新的 npm 會自動根據(jù)你使用的命令切換 registry:當你使用 publish, config, adduser, star 等(click here to see more) 命令時,會強制使用官方的 registry https://registry.npmjs.org;當你使用其它命令時,都會使用淘寶的鏡像https://registry.npm.taobao.org/。
如果要強制使用某個 registry 時,只要在命令后面添加 registry 參數(shù)即可,比如, npm install jquery --registry=https://r.cnpmjs.org 就會使用你指定的 registry 去拉取 jquery
如果要強制使用官方的 registry, 只要在命令后面加上 --npm 即可, 比如, npm install jquery --npm 就會使用官方的 registry 去拉取 jquery,(當鏡像沒有及時更新時,用此會選項很有效)
如果你想修改默認的淘寶鏡像或者官方的 registry,可以在你的環(huán)境變量中添加這兩個參數(shù):NPM_OFFICIAL_REGISTRY, NPM_MIRROR_REGISTRY,以此來修改默認的官方 registry 和 淘寶鏡像 registry
本地安裝也會替代了全局的 npm
express使用手冊
This is express China API.
其他
啟動mongodb腳本
#!/bin/bash
cd /home/daihuanqi/mongodb/bin/
./mongod --dbpath=../daihuanqi_db
后期作業(yè)不要用模板引擎!!