Mongodb查询耗时

SDHU SDHU 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
库中一共有四个实体,通过类似ef的框架关联起来,主要的其中3个实体TStudy,TSeries,TPatient如下:
这是TStudy
  [BsonId]
public string InstanceUID { get; set; }

[BsonElement("StudyID")]
public string StudyID { get; set; }

[BsonElement("StudyDate")]
public DateTime? StudyDate { get; set; }

[BsonElement("StudyTime")]
public DateTime? StudyTime { get; set; }

[BsonElement("Modility")]
public string Modility { get; set; }

[BsonElement("StudyDescription")]
public string StudyDescription { get; set; }

[BsonElement("IsCompleted")]
public int IsCompleted { get; set; }

[BsonElement("Patient")]
public TPatient Patient { get; set; }

[BsonElement("LockedState")]
public string LockedState { get; set; }

[BsonElement("Series")]
List<TSeries> _series;


这是Tseries:

[BsonIgnore]
public const string TBName = "tseries";

[BsonId]
public string InstanceUID { get; set; }

[BsonElement("SeriesNumber")]
public string SeriesNumber { get; set; }

[BsonElement("SeriesType")]
public string SeriesType { get; set; }

[BsonElement("ImageCount")]
public ushort ImageCount { get; set; }

[BsonElement("SeriesDescription")]
public string SeriesDescription { get; set; }

[BsonElement("ProtocolName")]
public string ProtocolName { get; set; }

[BsonElement("BodyPartExamined")]
public string BodyPartExamined { get; set; }

[BsonElement("StudyInstanceUID")]
public string StudyInstanceUID { get; set; }

[BsonElement("LockedState")]
public string LockedState { get; set; }

[BsonElement("Contrast")]
public bool? Contrast { get; set; }

[BsonElement("IsPreview")]
public bool? IsPreview { get; set; }

[BsonElement("ScanSeriesUID")]
public string ScanSeriesUID { get; set; }

[BsonElement("PacsAddress")]
public string PacsAddress { get; set; }

[BsonElement("PacsAE")]
public string PacsAE { get; set; }

[BsonElement("PrinterAE")]
public string PrinterAE { get; set; }


这是TPatient:

[BsonIgnore]
public const string TBName = "tpatient";

[BsonId]
public string StudyUID { get; set; }

[BsonElement("AccessionNumber")]
public string AccessionNumber { get; set; }

[BsonElement("PatientID")]
public string PatientID { get; set; }

[BsonElement("PatientName")]
public string PatientName { get; set; }

[BsonElement("Sex")]
public string Sex { get; set; }

[BsonElement("Birthday")]
public DateTime? Birthday { get; set; }

[BsonElement("Age")]
public string Age { get; set; }

[BsonElement("ReferringPhysician")]
public string ReferringPhysician { get; set; }

[BsonElement("Operator")]
public string Operator { get; set; }

[BsonElement("History")]
public string History { get; set; }

[BsonElement("StudyDescription")]
public string StudyDescription { get; set; }

[BsonElement("StudyDate")]
public DateTime? StudyDate { get; set; }

[BsonElement("StudyTime")]
public DateTime? StudyTime { get; set; }

[BsonElement("Editlogs")]
private List<TEditlog> _editlogs { set; get; }

然后通过以下方式查询到指定时间内的所有数据:

private IMongoCollection<TStudy> _studies => _database.GetCollection<TStudy>(TStudy.TBName);

var fromTimeFilter = Builders<TStudy>.Filter.Gt("StudyDate", fromTime);
var toTimeFilter = Builders<TStudy>.Filter.Lt("StudyDate", toTime);
var searchFilter = Builders<TStudy>.Filter.And(fromTimeFilter, toTimeFilter);
return _studies.Find(searchFilter).ToEnumerable();

上层界面获取到IEnumerable<TStudy> 类型的数据后直接绑定到datagrid,只有200组数据,但是下面的这段代码需要近两秒的时间,用mysql+Linq,从查询到显示结果花费的时间1s都不到,差距有点大,请问是我那里优化不对么?

我感觉是不是在_studies.Find(searchFilter).ToEnumerable() 返回的时候是不是mongo内部还没有真正将数据库中的数据映射到实体中, 直到数据源绑定的时候才开始映射数据,而映射的这一步又比较耗时么?






...全文

相关推荐

MongoDB如何查询耗时记录的方法详解

准备 在此之前,我们先在我们的数据库中插入10万条数据。数据的格式是这样的: { "name":"your name", "age":22, "gender":"male", "grade":2 } explain explain方法是用来查看db.collecion.find()的一些查询信息的。例如: db.collectionName.find().explain() explain方法有个可选的参数verbose,是个字符串,他表示的是verbose的模式。一共分为3种模式: queryPlanner:默认参数,详细说明查询优化器选择的计划并列出被拒绝的计划。例如: d

weixin_38626943

MongoDB查询性能优化验证及验证

主要介绍了MongoDB查询性能验证及优化的相关知识,涉及到MongoDB 查询优化原则知识点,本文介绍的非常详细,具有参考借鉴价值,感兴趣的朋友一起学习吧

weixin_38572960

MongoDB查询字段没有创建索引导致的连接超时异常解案例分享

主要介绍了MongoDB查询字段没有创建索引导致的连接超时异常解案例分享,本文是生产环境下总结而来,需要的朋友可以参考下

weixin_38626192

MongoDB数据库查询性能提高40倍的经历分享

大家在使用 MongoDB 的时候有没有碰到过性能问题呢?下面这篇文章主要给大家分享了MongoDB数据库查询性能提高40倍的经历,需要的朋友可以参考借鉴,下面来一起看看吧。

weixin_38679839

MongoDB性能测试报告

很详细的mongodb性能测试报告,从查询,插入,存储,多线程等进行了详尽的测试,图文并茂,很直观。

iehanbin
评论 2
收藏 已收藏
分享
返回顶部
SDHU
C# 111,129 成员 642,540 内容