Query to find the data in specific Time Range

Hello Everyone, My datetime is in measurement collection and my temperature value is in temperature value collection. I Need to find out at particular time period (ex - 09:00 am - 10:00 am) how many temperature values were recorded. I am using C# fro this.

Here is my measurement class:

using MongoDB.Entities;
using MongoDB.Bson;

 public class Measurement : Entity
        public DateTime DateRecorded { get; set; }
        public Many<TemperatureValues> TValues { get; set; }
        public Measurement()
            this.InitOneToMany(() => TValues);


This is TemperatureValue Class

 using MongoDB.Entities;
 using MongoDB.Bson;

 public class TemperatureValues : Entity
        public int TempSensorCount { get; set; }

        public short Values { get; set; }


Here is the data on my Measurement collection;



Here is the data on my TemperatureValue colllection;



Here is the auto generated Parent Child Id because of using Entity:



I tried this Query:

Measurement ms = new Measurement();
 var TemperaturDetails = await ( 
from j in ms.TValues.JoinQueryable() 
where j.ChildID ==Dateime("2021-09-20T11:44:39.829+00:00); join b in DB.Collection<Measurement>() on j.ParentID equals [
b.ID select b ).ToListAsync();

 Console.WriteLine($"temp : {TemperaturDetails.Count()}");

I believe this is the wrong approach:

May Be I need to write 2 queryies for this, In first I need to filter all the data in Measuremnet collection with time range. And in second query need to filter the count of temperature value in the time range.

Please do help me in writing the query.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.