• mongodb 数据分析


    GridFS

    Mongodb 文件存储之 GridFs,

    GridFS使用两个集合保存一个文件,fs.files与fs.chunks。可以使用下面的命令查看

    show collections

    fs.files集合包含了文件的元数据,使用命令查看

    db.fs.files.findOne();

    列出清单

    使用命令查看数据库中的文件的文档

    db.fs.files.find()

    mongofiles

    mongofiles是MongoDB提供的使用GridFS的命令行工具,使用示例如下:

    1. # 格式
    2. mongofiles <options> <command> <filename or _id or string>
    3. # command项
    4. list: 列出指定前缀的文件
    5. search: 列出包含指定字符串的文件
    6. put: 上传文件时指定文件名
    7. put_id: 上传文件时指定文件名和_id
    8. get: 获取指定文件名的文件
    9. get_id: 获取指定_id的文件
    10. delete:删除指定文件名的文件
    11. delete_id: 删除指定_id的文件

    上传文件

    使用GridFS的put命令保存文件。输入如下的命令,实现文件的上传

    mongofiles.exe -d gridfs put E:\elasticsearch-1.7.0.zip
     

    下载文件

    使用get命令下载文件

    mongofiles.exe -d gridfs get E:\elasticsearch-1.7.0.zip

    Map Reduce

    MongoDB Map Reduce

    Aggregate

    1. db.DevLogCollection.aggregate(
    2.    [
    3.      { $match: { Content: /心跳包数据发送/,DateTime:{ "$gt":ISODate("2022-09-14 00:00:00"),"$lt":ISODate("2022-09-15 00:00:00") } } },
    4.      { $group: {  _id : "$DeviceId", counts : {$sum : 1} }  }
    5.    ]
    6. );

    正常一天 1440个,超过则应算 2880个;
    如果允许最大一天离线1小时,即少60个;

    过滤[G2S]需要转义,因为[]在正则中有其含义;

    1. db.DevLogCollection.aggregate(
    2. [
    3. { $match: { Content: /^\[G2S\].*心跳包数据发送/,DateTime:{ "$gt":ISODate("2022-09-14 00:00:00"),"$lt":ISODate("2022-09-15 00:00:00") } } },
    4. { $group: { _id : "$DeviceId", counts : {$sum : 1} } }
    5. ]
    6. );

  • 相关阅读:
    Go通道机制与应用详解
    Springboot+学生作业管理系统 毕业设计-附源码251208
    leedCode_1:两数之和
    【0117】pg_multixact管理器
    angular 测试 api 说明
    2023NOIP A层联测10 集合
    推特API(Twitter API)V2 用户关注
    MySQL数据库管理及数据库基本操作
    以“防方视角”观Shiro反序列化漏洞
    我国数据安全治理研究
  • 原文地址:https://blog.csdn.net/Henry_Wu001/article/details/126877189