一、MongoDB安装及配置文章源自菜鸟学院-https://www.cainiaoxueyuan.com/sjk/4433.html
从官网(MongoDB下载)下载自己机器的版本:文章源自菜鸟学院-https://www.cainiaoxueyuan.com/sjk/4433.html
1 | [root@localhost ~]# wget -O mongodb.tar.gz https://www.mongodb.com/dr/fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-3.4.3.tgz |
解压并移动到安装目录,这里,我安装在/usr/local/目录文章源自菜鸟学院-https://www.cainiaoxueyuan.com/sjk/4433.html
1 2 | [root@localhost ~]# tar mongodb.tar.gz [root@localhost ~]# mv mongodb-linux-x86_64-rhel70-3.4.3/ /usr/local/mongodb |
创建数据存储目录及启动文章源自菜鸟学院-https://www.cainiaoxueyuan.com/sjk/4433.html
1 2 3 4 5 | [root@localhost ~]# mkdir -p /usr/local/mongdb/data [root@localhost ~]# /usr/local/mongdb/bin/mongod --dbpath=/usr/local/mongdb/data/ --fork --logpath=/var/log/mongdb.log --logappen about to fork child process, waiting until server is ready for connections. forked process: 3248 child process started successfully, parent exiting |
- 如上启动成功,参数解释:
- –dbpath 指定数据存储目录
- –fork 后台运行
- –logpath 日志存放地址
- –logappend 以追加方式记录日志
连接本地MongoDB及相关数据操作文章源自菜鸟学院-https://www.cainiaoxueyuan.com/sjk/4433.html
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | [root@localhost ~]# /usr/local/mongdb/bin/mongo MongoDB shell version v3.4.3 connecting to: mongodb://127.0.0.1:27017 MongoDB server version: 3.4.3 Server has startup warnings: 2017-04-18T17:56:54.290+0800 I CONTROL [initandlisten] 2017-04-18T17:56:54.290+0800 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database. 2017-04-18T17:56:54.291+0800 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted. 2017-04-18T17:56:54.291+0800 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended. 2017-04-18T17:56:54.291+0800 I CONTROL [initandlisten] 2017-04-18T17:56:54.291+0800 I CONTROL [initandlisten] 2017-04-18T17:56:54.291+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'. 2017-04-18T17:56:54.291+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never' 2017-04-18T17:56:54.291+0800 I CONTROL [initandlisten] 2017-04-18T17:56:54.291+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'. 2017-04-18T17:56:54.291+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never' 2017-04-18T17:56:54.291+0800 I CONTROL [initandlisten] 2017-04-18T17:56:54.295+0800 I STORAGE [initandlisten] 2017-04-18T17:56:54.295+0800 I STORAGE [initandlisten] ** WARNING: mongod started without --replSet yet 1 documents are present in local.system.replset 2017-04-18T17:56:54.295+0800 I STORAGE [initandlisten] ** Restart with --replSet unless you are doing maintenance and no other clients are connected. 2017-04-18T17:56:54.295+0800 I STORAGE [initandlisten] ** The TTL collection monitor will not start because of this. 2017-04-18T17:56:54.295+0800 I STORAGE [initandlisten] > > show dbs admin 0.000GB local 0.001GB test 0.001GB > > db.blog.insert({'title':'Licoril的个人博客','url':'http://www.leifc.com'}) WriteResult({ "nInserted" : 1 }) > > db.blog.find() { "_id" : ObjectId("58f5e5a5a16e65df16f75f4d"), "title" : "Licoril的个人博客", "url" : "http://www.leifc.com" } > |
以上就是列出数据库,插入文档与查询文档基本操作文章源自菜鸟学院-https://www.cainiaoxueyuan.com/sjk/4433.html