zoukankan      html  css  js  c++  java
  • MongoDB基本管理命令

    基本命令http://www.cnblogs.com/Joans/p/3729914.html

      

     检查是否在运行:

    ps -ef  |  grep   mongo
    netstat  -an  |  grep   27017


    Open the port on firewall:
    firewall-cmd --zone=public --add-port=27017/tcp --permanent

    firewall-cmd --reload
    
    

    Mongodbpymongo.errors.ServerSelectionTimeoutError: ip:27017: timed out

    • telnet ip 27017 发现端口不通
    • 在mongodb所在服务器的防火墙中开放此端口开放端口:firewall-cmd --zone=public --add-port=27017/tcp --permanent
      重新载入:firewall-cmd --reload查看:firewall-cmd --zone= public --query-port=27017/tcp

    • 再次连接OK


    1、指定字段排序、第一个
    db.collection.find({条件}).sort({“a”:-1}).limit(1)
    
    

      2、导出

    $ mongoexport --help
    Export MongoDB data to CSV, TSV or JSON files.
    
    Options:
      --help                                produce help message
     --quiet                               silence all non error diagnostic  messages 
      -h [ --host ] arg                     mongo host to connect to ( <set name>/s1,s2 for sets)  主机名 默认127.0.0.1
      --port arg                            server port. Can also use --host hostname:port  端口 默认27017
      -u [ --username ] arg                 username 用户名
      -p [ --password ] arg                 password 密码
      -d [ --db ] arg                       database to use 数据库名
      -c [ --collection ] arg               collection to use (some commands)  集合名
      -f [ --fields ] arg                   comma separated list of field names  e.g. -f name,age 字段名,导出到csv时候需要
      --fieldFile arg                       file with field names - 1 per line
      --csv                                 export to csv instead of json  导出csv格式
      -o [ --out ] arg                      output file; if not specified, stdout  is used 导出文件名
      -q [ --query ] arg                    query filter, as a JSON string, e.g., '{x:{$gt:1}}'  查询条件,使用json格式
      --skip arg (=0)                       documents to skip, default 0  跳过数据,偏移,默认为0
      --limit arg (=0)                      limit the numbers of documents returned, default all 限制返回的documents数量,默认为0
      --sort arg                            sort order, as a JSON string, e.g.,  '{x:1}' 排序
    ./mongoexport  -h "127.0.0.1" -d database名称 -c 集合名 -o Booking.csv --type csv -f "Request,Response,InputTime,Duration,LogType"

    命令参考:http://www.cnblogs.com/qingtianyu2015/p/5968400.html

  • 相关阅读:
    Objective-C-使用NSMutableURLRequest发送POST请求,使用NSJSONSerialization解析JSON字符串
    js showModalDialog打开新的页面给原页面传值问题
    svn2git使用小记
    模拟等待事件row lock waits
    URAL 1994 The Emperor's plan 求组合数 大数用log+exp处理
    struts总结
    URAL 1992 CVS 链表
    android游戏物理引擎开发——粒子系统(三)
    状态模式与上机
    OpenCV——凸包
  • 原文地址:https://www.cnblogs.com/tianboblog/p/6946964.html
Copyright © 2011-2022 走看看