I want to delete all documents with timestamp after “17-06-2024 23h59”, BUT my timestamp is outside the “metadata” field. Example one of my document :
{
"ts": {
"$date": "2021-03-24T19:40:00.000Z"
},
"metadata": {
"sensorsId": "whatever"
},
"locationUUID": "whatever",
"_id": {
"$oid": "whatever"
},
"data": {
"temperature": {"$numberDecimal": "21.4"}
}
}
Here’s my code :
filter_criteria = {'timestamp': {'$gt': datetime.datetime(2024, 6, 17,23,59)}}
documents = collection.find(filter_criteria)
document_ids = [doc['_id'] for doc in documents]
results = sensors_comfort.delete_many({'_id': {'$in': document_ids}})
But i got this error :
pymongo.errors.WriteError: Cannot perform an update or delete on a time-series collection when querying on a field that is not the metaField 'metadata', full error: {'index': 0, 'code': 72, 'errmsg': "Cannot perform an update or delete on a time-series collection when querying on a field that is not the metaField 'metadata'"}