zoukankan      html  css  js  c++  java
  • 【原创】大数据基础之Mongodb(2)常用查询命令

    1 下载

    https://www.mongodb.com/download-center/community

    比如:

    https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-4.0.9.tgz

    2 连接

    # cd $MONGODB_HOME
    # bin/mongo master:27017/database_name

    3 查询

    1 count

    >db.getCollection('table_name').find({}).count()

    2 group by

    >db.getCollection('table_name').aggregate([{"$group": {_id: "$column_name", count: {"$sum": 1}}}])

    3 select by limit

    >db.getCollection('table_name').find({}).limit(1).pretty()

    4 select by condition ‘=’

    >db.getCollection('table_name').find({"column_name": "column_value"})

    5 select by condition ‘>’

    >db.getCollection('table_name').find({"column_name":{$gt:"column_value"}}).pretty()

    6 select by condition ‘or’

    >db.getCollection('table_name').find({$or: [ {"column_name1":"column_value1"},{"column_name2":{$gt:"column_value2"}}]}).pretty()

    7 select by date range

    >db.getCollection('table_name').find({"create_time":{$gte:ISODate("2019-05-18T00:00:00Z"),$lt:ISODate("2019-05-19T00:00:00Z")}})

    8 map reduce - 词频统计

    统计信息

    >db.table_name.mapReduce(function(){ emit(this.column,1);}, function(key, values){return Array.sum(values);}, {out:"post_total"})

    输出结果

    >db.table_name.mapReduce(function(){ emit(this.column,1);}, function(key, values){return Array.sum(values);}, {out:"post_total"}).find() 

    默认只输出20行结果,然后需要不断输入it才能输出更多结果,如果想一次输出全部结果,可以先执行

    >DBQuery.shellBatchSize = 100000;

  • 相关阅读:
    shell 实现word count
    jvm 参数调优
    Java注解处理器(转)
    JVM -XX: 参数介绍(转)
    如何在Linux下重命名多个文件
    Kafka学习之broker配置(0.8.1版)(转)
    linux 历史命令用法(转)
    hive-site.xml 参数设置
    Hadoop-2.2.0 + Hbase-0.96.2 + Hive-0.13.1(转)
    正则表达式通过Unicode属性匹配
  • 原文地址:https://www.cnblogs.com/barneywill/p/10874146.html
Copyright © 2011-2022 走看看