'mongodb filtering timeseries data

i am new to mongodb and want to filter data in chunks in a way that they follow timeseries

currently i have this

def iterate_by_chunks(collection, chunksize=1, start_from=0, query={}, projection={}):
   chunks = range(start_from, collection.count_documents(query), int(chunksize))
   num_chunks = len(chunks)
   for i in range(1, num_chunks +1):
      if i < num_chunks:
          yield collection.find(query, projection=projection)[chunks[i -1]:chunks[i]]
      else:
          yield collection.find(query, projection=projection)[chunks[i -1]:chunks.stop]

_filter = {
    'metadata.temperature': { '$gt':  0.79, '$lt': 0.9 },
    'metadata.sensor': { '$gt':  0.8, '$lt': 0.81 },
}
for d in iterate_by_chunks(collection, chunksize=2, query=_filter):
    #print(len(list(d)))
    for doc in d:
        print(str(doc['datetime']))
    print('---')

and it will output

2021-01-22 03:00:00
2021-01-22 03:30:00
---
2021-01-22 03:15:00
2021-02-23 16:00:00
---

is it possible to make it continuous that way it would output

2021-01-22 03:00:00
2021-01-22 03:15:00
---
2021-01-22 03:30:00
---
2021-02-23 16:00:00
--- 

two chunks of timeseries data that they follow time and if they are not in same 30 minutes (2 chunks per 15 min) to skip it?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source