• mongodb数据库操作


    1、启动mongodb

    1. /usr/local/mongodb/bin/mongod --dbpath /var/mongodb/data/
    2. --logpath /var/mongodb/logs/log.log &

    mongodb启动命令中

    --dbpath 指定mongodb的数据存储路径

    --logpath 指定mongodb的日志存储路径

    2、停止mongodb

    第一步先进入mongo命令行模式

    第二步,使用use admin 命令进入admin数据库

    第三步,执行 db.shutdownServer()命令 停止服务。代码及显示如下:

    1. [root@localhost data]# mongo
    2. MongoDB shell version: 2.4.14
    3. connecting to: test
    4. Server has startup warnings:
    5. 2019-06-20T17:59:54.575+0800 I STORAGE [initandlisten]
    6. 2019-06-20T17:59:54.575+0800 I STORAGE [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
    7. 2019-06-20T17:59:54.575+0800 I STORAGE [initandlisten] ** See http://dochub.mongodb.org/core/prodnotes-filesystem
    8. 2019-06-20T17:59:55.404+0800 I CONTROL [initandlisten]
    9. 2019-06-20T17:59:55.404+0800 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
    10. 2019-06-20T17:59:55.404+0800 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
    11. 2019-06-20T17:59:55.404+0800 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
    12. 2019-06-20T17:59:55.404+0800 I CONTROL [initandlisten]
    13. 2019-06-20T17:59:55.405+0800 I CONTROL [initandlisten]
    14. 2019-06-20T17:59:55.405+0800 I CONTROL [initandlisten] ** WARNING: You are running on a NUMA machine.
    15. 2019-06-20T17:59:55.405+0800 I CONTROL [initandlisten] ** We suggest launching mongod like this to avoid performance problems:
    16. 2019-06-20T17:59:55.405+0800 I CONTROL [initandlisten] ** numactl --interleave=all mongod [other options]
    17. 2019-06-20T17:59:55.405+0800 I CONTROL [initandlisten]
    18. 2019-06-20T17:59:55.405+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
    19. 2019-06-20T17:59:55.405+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never'
    20. 2019-06-20T17:59:55.405+0800 I CONTROL [initandlisten]
    21. 2019-06-20T17:59:55.405+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
    22. 2019-06-20T17:59:55.405+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never'
    23. 2019-06-20T17:59:55.405+0800 I CONTROL [initandlisten]
    24. > use admin
    25. switched to db admin
    26. > db.shutdownServer()
    27. Thu Jun 20 18:01:16.276 DBClientCursor::init call() failed
    28. server should be down...
    29. Thu Jun 20 18:01:16.277 trying reconnect to 127.0.0.1:27017
    30. Thu Jun 20 18:01:16.277 reconnect 127.0.0.1:27017 failed couldn't connect to server 127.0.0.1:27017
    31. >

     2 、导出Mongodb数据

    [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指定导出的文件夹

  • 相关阅读:
    设计模式笔记 ——1(结构体的私有属性)
    程序员如何悄悄拔尖,然后惊艳四座?
    Flink日志采集-ELK可视化实现
    【大数据Hive】hive 加载数据常用方案使用详解
    HttpClient笔记
    Pinctrl 子系统简介
    玄机科技闪耀中国国际动漫节,携手百度共绘 AI 国漫新篇章
    总结文件系统相关知识
    解决交叉编译的依赖问题
    Java学生管理系统
  • 原文地址:https://blog.csdn.net/tianlong1569/article/details/93081306