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:
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,
is there a convertToTimeseries planned, as there is a convertToCapped?
Hi @conrad and welcome to MongoDB community forums!!
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.
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.