zoukankan      html  css  js  c++  java
  • C#操作mongodb(聚合函数)-分组找出每组的最大值

     public static void OnQuery_QXData(string DBName, string tablename,string layername)
            {
                if (ConnectionString == null) OnCreateDB();
                MoDataBase = MoClient.GetDatabase(DBName);
                var collection = MoDataBase.GetCollection<BsonDocument>(tablename);           

                //{$group:{_id:{stationID:"$stationID",stationName:"$stationName"},TimeData:{$max:"$TimeData"},eValue:{$last:"$eValue"}}}           

                var group = new BsonDocument {

                    {"_id",new BsonDocument
                    {
                        {"stationID","$stationID"},
                        {"stationName","$stationName" }
                    }
            },
                    //{"stationID",new BsonDocument{ { "stationID", "$stationID" } } },
                    {"stationID",new BsonDocument("$last","$stationID")},
                    { "TimeData",new BsonDocument("$max","$TimeData")},
                    {"eValue" ,new BsonDocument("$last","$eValue")}
                };
                var list = collection.Aggregate().Group(group).ToListAsync().Result;
                double value = 0.0;
                foreach (BsonDocument bsondoc in list)
                {
                   
                    double  evalue = double.TryParse(bsondoc.GetElement("eValue").Value.ToString(),out value)?value:0;
                    string stationid = bsondoc.GetElement("stationID").Value.ToString();              
                }
            }
        }
    }

  • 相关阅读:
    paramiko连接并配置交换机
    Paramiko-sftp上传和下载文件
    常做的性能测试包含哪些?
    术语?
    什么是【负载测试】和【压力测试】?
    什么是性能?
    web服务器
    兼容性测试?
    可用性测试?
    什么是【回归测试】?
  • 原文地址:https://www.cnblogs.com/wjr0117/p/9020092.html
Copyright © 2011-2022 走看看