How to update an existing timeseries collection?

I am using pymongo and a command which automatically creates a collection for each customer in my system. Normally I would just insert one document and delete it, which assured that the collection exists or is created if not. Now I would like to switch to timeseries collections, however this complicates things. For creation I need to use the create_collection command, which is already unhandy, as I need to call list_collection_names before to confirm that the collection doesn’t exist already. The two questions I have are:

  1. is it possible to update a timeseries collections options? I tried using “collMod”, which threw me "collmod.timeseries.timefield" is an unknown field. I also would love to ensure that it really is a timeseries collection so,
  2. is there a convertToTimeseries planned, as there is a convertToCapped?

Hi @conrad and welcome to MongoDB community forums!! :wave:

It would be helpful for us to provide you could help me understand why do you need to create a collection for every customer as this would result in multiple collections having redundant field names.

Could you also help me understand the use case in order to move from simple collection to a time series collection.

I believe this would be needed even if you create a non time series collection, you would need to use list_collection_names to view before you are trying to insert into new collection.

However, to answer your questions,

At this point as mentioned in the documentation for Limitations In Time Series collection, the delete and update have some limitations. Therefore, this might not be available at the supported drivers as well.

If you have a specific feature request or suggestion that you would like to see implemented in MongoDB, we encourage you to share it in the MongoDB Feedback Engine.

Let us know if you have any further questions.

Regards
Aasawari

Thank you for your answer.

This is a security measure on our end so that programmers on our side can only access by definition the collection for the specific customer. Separating the data made our whole process a lot simpler.

We only store sensor data in mongoDB, but we are doing this for the last couple of years and now that the TimeSeries collection exist, we would like to use it to improve performance of queries etc.

No it actually isn’t. At the moment we add and delete a specific document, which automatically creates a collection if it doesn’t exist.

I am not talking about update and deletion calls, but update on the collection itself. The driver shouldn’t be an issue as I could just plainly use the mongodb commands if it would be possible.

Hi @conrad

Apologies for writing late.

To answer your question regarding convertToTimeseries, as of today we do not have the capability to do so. This is because the time Series collection in MongoDB is implemented in a way that it is a view to system.bucket.collection.

Could you kindly verify if the proposed insert and delete workflow aims to prevent excessive privileges? Are you using the built-in readWrite role in MongoDB? Have any custom roles been established, or are there other security measures in place for this purpose?
In saying so, there could one potential solution if it works for your use case is to create an API layer between MongoDB and the user. That way, you can restrict database operations in a more granular manner (e.g. you can ensure a collection exists without the need to do the insert-delete workflow).
However this flexibility comes with additional maintenance, so this may not work for all use cases.

Let us know if this work for your use case.

Regards
Aasawari