实践MongoDB之二安装和入门

installation

环境信息:deepin linux 15.4.1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
$ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6
Executing: /tmp/apt-key-gpghome.0sL1yEPGQX/gpg.1.sh --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6
gpg: 密钥 BC711F9BA15703C6:公钥“MongoDB 3.4 Release Signing Key <packaging@mongodb.com>”已导入
gpg: 合计被处理的数量:1
gpg:           已导入:1

$ echo "deb http://repo.mongodb.org/apt/debian jessie/mongodb-org/3.4 main" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list
deb http://repo.mongodb.org/apt/debian jessie/mongodb-org/3.4 main

$ sudo apt-get update
命中:1 http://packages.deepin.com/deepin panda InRelease
忽略:2 http://repo.mongodb.org/apt/debian jessie/mongodb-org/3.4 InRelease
命中:3 https://download.docker.com/linux/debian jessie InRelease
获取:4 http://repo.mongodb.org/apt/debian jessie/mongodb-org/3.4 Release [2,393 B]
命中:5 https://deb.opera.com/opera-stable stable InRelease
获取:6 http://repo.mongodb.org/apt/debian jessie/mongodb-org/3.4 Release.gpg [801 B]
获取:7 http://repo.mongodb.org/apt/debian jessie/mongodb-org/3.4/main amd64 Packages [5,277 B]
已下载 8,471 B,耗时 3秒 (2,606 B/s)
正在读取软件包列表... 完成
$ sudo apt-get install -y mongodb-org

默认配置文件:/etc/mongod.conf

默认数据存储路径:/var/lib/mongodb

默认服务地址:127.0.0.1:27017

mongd服务:

1
2
3
4
5
$ sudo systemctl status mongod.service 
● mongod.service - High-performance, schema-free document-oriented database
   Loaded: loaded (/lib/systemd/system/mongod.service; disabled; vendor preset: enabled)
   Active: inactive (dead)
     Docs: https://docs.mongodb.org/manual

console

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
$ mongo
MongoDB shell version v3.4.5
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.4.5
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-27T10:43:14.139+0800 I STORAGE  [initandlisten]
2017-06-27T10:43:14.139+0800 I STORAGE  [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
2017-06-27T10:43:14.139+0800 I STORAGE  [initandlisten] **          See http://dochub.mongodb.org/core/prodnotes-filesystem
2017-06-27T10:43:15.939+0800 I CONTROL  [initandlisten]
2017-06-27T10:43:15.939+0800 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2017-06-27T10:43:15.939+0800 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2017-06-27T10:43:15.939+0800 I CONTROL  [initandlisten]
> use tutorial
switched to db tutorial
> 

GUI client

Robo 3T (formerly Robomongo) is the free lightweight GUI available for Windows, Mac, and Linux for MongoDB enthusiasts.

Studio 3T is the MongoDB GUI and IDE available for Windows, Mac, and Linux. Free for non-commercial.

get started

mongodb中的collection类似与RMDBS中的table

#唯一,手动设定或者mongodb自动生成

_id, ObjectID

# 切换到tutorial数据库,不需要显示创建database和collection(除非设置为strict模式)

> use tutorial

db.<collection>.<command>

command: insert/remove/update/find/count

db.getCollectionNames()