1、使用聚合取最新的实时数据(每一个测站有多条数据,取日期最新的数据。也就是每个测站取最新的值)

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 collection = MoDataBase.GetCollection<BsonDocument>(tablename);
 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 : ;
string stationid = bsondoc.GetElement("stationID").Value.ToString();

2、普通的按照排序取最新的数据

如果一个测站一个表名

/// <summary>
/// 获取数据库中每条数据对应的时间放到图表的横坐标上
/// </summary>
/// <param name="StatioID">监测站ID</param>
/// <param name="PullutionID">指标类型</param>
/// <returns></returns>
public static List<string> GetChartData(string StatioID, string PullutionID,string StartTime,string EndTime)
{
List<string> XData = new List<string>();
if (ConnectionString == null) OnCreateDB();
MoDataBase = MoClient.GetDatabase("SSMonitor");
BsonDocument bsonDoc = new BsonDocument();
bsonDoc.Add("TimeData", new BsonDocument() { { "$gte", DateTimeToInt(StartTime) }, { "$lte", DateTimeToInt(EndTime) } });
var collection = MoDataBase.GetCollection<BsonDocument>(string.Format("{0}_{1}_Day", StatioID, PullutionID));
var sort = Builders<BsonDocument>.Sort.Ascending("TimeData");
var list = collection.Find(bsonDoc).Sort(sort).ToList();
foreach (BsonDocument bsondoc in list)
{
string time = bsondoc.GetElement("MonitorTime").Value.ToString();
XData.Add(time);
}
return XData;
}

最新文章

  1. 解决eclipse配置Tomcat时找不到server选项(Mac通用)
  2. linux bash &amp; profile &amp;bash_profile 小结
  3. [No000021]跟维多利亚学英语
  4. validate
  5. 操作系统基础知识之————单线程(Thread)与多线程的区别
  6. sql取年月日
  7. log4j 应用
  8. ID3算法 决策树的生成(1)
  9. TAxThread - Inter thread message based communication - Delphi
  10. 【剑指offer】二叉树中和为某一值的路径
  11. MYSQL主从同步测试
  12. 无限循环的ViewPager
  13. python面对对象编程----2:__init__
  14. storm搭建(1)zookeeper搭建
  15. [POJ1631] nlogn求LIS
  16. Postgresql 创建SEQUENCE,Springboot中使用KeyHolder
  17. (Python3) 求中位数 代码
  18. Java链接MySQL数据库的用配置文件和不用配置文件的代码
  19. 洛谷P3235 [HNOI2014]江南乐(Multi-SG)
  20. StringBuffer作为参数传递的问题

热门文章

  1. jeecg数据库切换至mysql8.0方式
  2. 如何更换linux shell中所显示目录的颜色?
  3. python开发--Python实现延时操作的几种方式
  4. FineReport简单上手
  5. Win64 驱动内核编程-33.枚举与删除对象回调
  6. IPv4分类
  7. a dynamic resume
  8. Java 8之Map新增方法&lt;转&gt;
  9. 基于传统方法点云分割以及PCL中分割模块
  10. jzy3D从入门到弃坑_4尝试使用jzy3D1.0画图失败