I have a simple Time Series collection created with the following parameters:
timeseries: {
timeField: "timestamp",
granularity: "seconds"
}
The documents contain data about the market price of some asset. Due to a change on how the price is calculated, I need to delete the documents between two dates, before re-inserting the documents with corrections.
But according to the doc, delete commands on Time Series collections have the following limitation:
The query may only match on metaField field values.
I am new to MongoDB so I’m probably missing something here, but I do not understand this limitation:
- The
timeField
being the main index for a time series, why can’t it be used to match the documents? - Do I misunderstand what Time Series collections are meant for?
- How can I delete the documents between two dates? Right now, I’m thinking of adding the document timestamp in
metaField
, but this duplication feels completely unnecessary and I wonder how performance will be affected.
In case it helps to answer my question, this is how I wanted to do this operation, using the following Go code:
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)
This fails with the following error: Cannot perform an update or delete on a time-series collection when querying on a field that is not the metaField
.