-
简单介绍:
MongoDB是一个基于分布式文件存储的数据库,由c++语言编写,为WEB应用提供可扩展的高性能数据存储解决方案。MongoDB属于非关系数据库,也不能说完全属于,更像是介于关系数据库和非关系数据库之间的产品,是非关系数据库中功能最丰富,很像关系型数据库 -
下载安装教程:https://www.mongodb.org.cn/tutorial/55.html
image.png
启动:
在你的安装目录/bin下,有一个叫mongod.exe的应用程序,这个程序就是用来启动你的mongodb服务器的。
创建数据库目录
在你想要存放数据的地方(随便哪个磁盘都可以),新建一个文件夹,如db,我们推荐的数据库目录设置是:
-
启动数据库
我本地是window10环境,我的mongodb服务安装在E盘的day1\data文件夹。我的数据目录在E盘的day1的data文件夹。 image.png
2019-07-08T20:50:25.381+0800 I CONTROL [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
2019-07-08T20:50:25.386+0800 I CONTROL [initandlisten] MongoDB starting : pid=5588 port=27017 dbpath=E:\day01\data\db 64-bit host=OS-20190616DQJE
2019-07-08T20:50:25.387+0800 I CONTROL [initandlisten] targetMinOS: Windows 7/Windows Server 2008 R2
2019-07-08T20:50:25.388+0800 I CONTROL [initandlisten] db version v4.0.10
2019-07-08T20:50:25.388+0800 I CONTROL [initandlisten] git version: c389e7f69f637f7a1ac3cc9fae843b635f20b766
2019-07-08T20:50:25.389+0800 I CONTROL [initandlisten] allocator: tcmalloc
2019-07-08T20:50:25.389+0800 I CONTROL [initandlisten] modules: none
2019-07-08T20:50:25.390+0800 I CONTROL [initandlisten] build environment:
2019-07-08T20:50:25.390+0800 I CONTROL [initandlisten] distmod: 2008plus-ssl
2019-07-08T20:50:25.390+0800 I CONTROL [initandlisten] distarch: x86_64
2019-07-08T20:50:25.391+0800 I CONTROL [initandlisten] target_arch: x86_64
2019-07-08T20:50:25.391+0800 I CONTROL [initandlisten] options: { storage: { dbPath: "E:\day01\data\db" } }
2019-07-08T20:50:25.398+0800 I STORAGE [initandlisten] Detected data files in E:\day01\data\db created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'.
2019-07-08T20:50:25.398+0800 I STORAGE [initandlisten] wiredtiger_open config: create,cache_size=3548M,session_max=20000,eviction=(threads_min=4,threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),statistics_log=(wait=0),verbose=(recovery_progress),
2019-07-08T20:50:25.652+0800 I STORAGE [initandlisten] WiredTiger message [1562590225:652303][5588:140707988594256], txn-recover: Main recovery loop: starting at 1/36736 to 2/256
2019-07-08T20:50:25.774+0800 I STORAGE [initandlisten] WiredTiger message [1562590225:774251][5588:140707988594256], txn-recover: Recovering log 1 through 2
2019-07-08T20:50:25.860+0800 I STORAGE [initandlisten] WiredTiger message [1562590225:860182][5588:140707988594256], txn-recover: Recovering log 2 through 2
2019-07-08T20:50:25.922+0800 I STORAGE [initandlisten] WiredTiger message [1562590225:922150][5588:140707988594256], txn-recover: Set global recovery timestamp: 0
2019-07-08T20:50:26.040+0800 I RECOVERY [initandlisten] WiredTiger recoveryTimestamp. Ts: Timestamp(0, 0)
2019-07-08T20:50:26.191+0800 I CONTROL [initandlisten]
2019-07-08T20:50:26.191+0800 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2019-07-08T20:50:26.192+0800 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2019-07-08T20:50:26.193+0800 I CONTROL [initandlisten]
2019-07-08T20:50:26.194+0800 I CONTROL [initandlisten] ** WARNING: This server is bound to localhost.
2019-07-08T20:50:26.194+0800 I CONTROL [initandlisten] ** Remote systems will be unable to connect to this server.
2019-07-08T20:50:26.195+0800 I CONTROL [initandlisten] ** Start the server with --bind_ip <address> to specify which IP
2019-07-08T20:50:26.195+0800 I CONTROL [initandlisten] ** addresses it should serve responses from, or with --bind_ip_all to
2019-07-08T20:50:26.196+0800 I CONTROL [initandlisten] ** bind to all interfaces. If this behavior is desired, start the
2019-07-08T20:50:26.196+0800 I CONTROL [initandlisten] ** server with --bind_ip 127.0.0.1 to disable this warning.
2019-07-08T20:50:26.197+0800 I CONTROL [initandlisten]
2019-07-08T20:50:26.610+0800 I FTDC [initandlisten] Initializing full-time diagnostic data capture with directory 'E:/day01/data/db/diagnostic.data'
2019-07-08T20:50:26.613+0800 I NETWORK [initandlisten] waiting for connections on port 27017
2019-07-08T20:50:32.135+0800 I NETWORK [listener] connection accepted from 127.0.0.1:58791 #1 (1 connection now open)
2019-07-08T20:50:32.167+0800 I NETWORK [conn1] received client metadata from 127.0.0.1:58791 conn1: { application: { name: "MongoDB Shell" }, driver: { name: "MongoDB Internal Client", version: "4.0.10" }, os: { type: "Windows", name: "Microsoft Windows 10", architecture: "x86_64", version: "10.0 (build 18362)" } }
2019-07-08T20:50:34.036+0800 I NETWORK [listener] connection accepted from 127.0.0.1:58796 #2 (2 connections now open)
2019-07-08T20:50:34.038+0800 I NETWORK [conn2] received client metadata from 127.0.0.1:58796 conn2: { driver: { name: "mongo-java-driver", version: "C_4.4.1-189-g33e62f7-dirty" }, os: { type: "Windows", name: "Windows 10", architecture: "amd64", version: "10.0" }, platform: "Java/Oracle Corporation/1.8.0_121-b13" }
2019-07-08T20:57:26.641+0800 I STORAGE [conn1] createCollection: hcc1222.student with generated UUID: 48c40b59-90e8-444e-84ad-f954fcfd3bc9
2019-07-08T20:58:15.987+0800 I NETWORK [listener] connection accepted from 127.0.0.1:60790 #3 (3 connections now open)
2019-07-08T20:58:15.988+0800 I NETWORK [conn3] received client metadata from 127.0.0.1:60790 conn3: { driver: { name: "mongo-java-driver", version: "C_4.4.1-189-g33e62f7-dirty" }, os: { type: "Windows", name: "Windows 10", architecture: "amd64", version: "10.0" }, platform: "Java/Oracle Corporation/1.8.0_121-b13" }
2019-07-08T20:58:17.776+0800 I NETWORK [listener] connection accepted from 127.0.0.1:60800 #4 (4 connections now open)
2019-07-08T20:58:17.779+0800 I NETWORK [conn4] received client metadata from 127.0.0.1:60800 conn4: { driver: { name: "mongo-java-driver", version: "C_4.4.1-189-g33e62f7-dirty" }, os: { type: "Windows", name: "Windows 10", architecture: "amd64", version: "10.0" }, platform: "Java/Oracle Corporation/1.8.0_121-b13" }
表示mongodb服务器已经启动,正在60800窗口等待连
再查看E:\day01\data文件夹,已出现以下文件:
image.png
表示mongodb服务启动成功。
可视化mongoDB工具:mongochef.exe
个人已经下载好:
https://pan.baidu.com/s/1a66OyUav1QmKxt6Y-158oA
提取码:0p9b
这里已经安装好:
安装流程参照:
https://jingyan.baidu.com/article/6181c3e0be3173152ef153cf.html
MongoDB基本操作
另外打开cmd窗口启动 image.png一 操作mongodb数据库
1,创建数据库
语法:use 数据库名
注意:如果数据库不存在,则创建数据库,否则就切换到指定的数据库
2,删除数据库:
前提:使用当前数据库(use 数据库名)
db.dropDatabase()
3,查看所有数据:
show dbs
注意:如果刚刚创建的数据库不在表类,如果要显示它,我们需要向刚刚创建的数据库插入一些数(db.student.insert({name:"tom",age:18,gender:1,address:"北京",isDelete:0})
4,查看当前正在使用的数据库
a, db
b, db.getName()
5,断开连接
exit
6, 查看命令api
help
image.png
二,集合操作
待续...
三,文档操作
待续..
网友评论