1、启动mongodb
/usr/local/mongodb/bin/mongod --dbpath /var/mongodb/data/
--logpath /var/mongodb/logs/log.log &
在mongodb启动命令中
--dbpath 指定mongodb的数据存储路径
--logpath 指定mongodb的日志存储路径
2、停止mongodb
第一步先进入mongo命令行模式
第二步,使用use admin 命令进入admin数据库
第三步,执行 db.shutdownServer()命令 停止服务。代码及显示如下:
[root@localhost data]# mongo
MongoDB shell version: 2.4.14
connecting to: test
Server has startup warnings:
2019-06-20T17:59:54.575+0800 I STORAGE [initandlisten]
2019-06-20T17:59:54.575+0800 I STORAGE [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
2019-06-20T17:59:54.575+0800 I STORAGE [initandlisten] ** See http://dochub.mongodb.org/core/prodnotes-filesystem
2019-06-20T17:59:55.404+0800 I CONTROL [initandlisten]
2019-06-20T17:59:55.404+0800 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2019-06-20T17:59:55.404+0800 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2019-06-20T17:59:55.404+0800 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2019-06-20T17:59:55.404+0800 I CONTROL [initandlisten]
2019-06-20T17:59:55.405+0800 I CONTROL [initandlisten]
2019-06-20T17:59:55.405+0800 I CONTROL [initandlisten] ** WARNING: You are running on a NUMA machine.
2019-06-20T17:59:55.405+0800 I CONTROL [initandlisten] ** We suggest launching mongod like this to avoid performance problems:
2019-06-20T17:59:55.405+0800 I CONTROL [initandlisten] ** numactl --interleave=all mongod [other options]
2019-06-20T17:59:55.405+0800 I CONTROL [initandlisten]
2019-06-20T17:59:55.405+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2019-06-20T17:59:55.405+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2019-06-20T17:59:55.405+0800 I CONTROL [initandlisten]
2019-06-20T17:59:55.405+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2019-06-20T17:59:55.405+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2019-06-20T17:59:55.405+0800 I CONTROL [initandlisten]
> use admin
switched to db admin
> db.shutdownServer()
Thu Jun 20 18:01:16.276 DBClientCursor::init call() failed
server should be down...
Thu Jun 20 18:01:16.277 trying reconnect to 127.0.0.1:27017
Thu Jun 20 18:01:16.277 reconnect 127.0.0.1:27017 failed couldn't connect to server 127.0.0.1:27017
>
2 、导出Mongodb数据文章来源:https://www.toymoban.com/news/detail-700019.html
[root@localhost back-mongo]# mongoexport -h 127.0.0.1:27017 -d trail -c location -o /home/back-mongo/show.csv
mongoexport用于导入csv或json或txt数据, 其中-h指定Mongo服务地址,-d指定导出哪个数据为,-c指定导出哪个表,-o指定导出的文件夹文章来源地址https://www.toymoban.com/news/detail-700019.html
到了这里,关于mongodb数据库操作的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!