Hi everyone,
I am Darshan Hiranandani, working with a Time Series collection in MongoDB and I’m facing an issue when trying to delete documents between two dates. Here are the parameters for my collection:
timeseries: {
timeField: "timestamp",
granularity: "seconds"
}
The collection contains market price data for an asset, and due to a change in the price calculation, I need to delete documents within a specific date range before reinserting them with corrections.
However, I’m encountering a limitation when trying to delete documents based on the timestamp field. According to the documentation, delete commands on Time Series collections only support queries matching metaField values.
This is where I get confused:
For reference, this is how I’ve attempted the operation in Go
filter := bson.D{{
Key: "timestamp",
Value: bson.D{
{
Key: "$gte",
Value: timestamp_start,
},
{
Key: "$lt",
Value: timestamp_end,
},
},
}}
result, err := coll.DeleteMany(context.TODO(), filter)
But I’m getting this error:
"Cannot perform an update or delete on a time-series collection when querying on a field that is not the metaField."
Has anyone else run into this issue or found a workaround? Any help would be greatly appreciated!
Regards
Darshan Hiranandani