Start a new topic

New Collection for each user

I've been thinking about creating a new collection for each user I have. Is there a way to create a new collection using business logic whenever a new user is created? Are there any negatives I should know about? I'm not sure if there would be performance issues or if there are any limits to the number of collections. Thanks for your time!

Hi Oliver,


You don't need to create a collection specifically. If you run an insert query for a new collection name, the new collection will be created automatically and the data will be inserted. This is because Kinvey uses mongoDB in the backend and that's how mongoDB works.


Previously, I got the impression that the first insert needs to happen at the time of user creation. That's why I suggested onPostSave BL. If that's not the case, then you can skip that part altogether and call the first insert statement whenever you get the first log from the new users' devices.


As for the reason to not recommend it, this will become a bit difficult to manage as the number of users grows. Also, if you want run aggregation/ETL on the data in the future, it will help if you have single/few collections. And with hundreds/thousands of collections, you might run into issues while accessing the data in console as well.


If you want to keep the data separate from a security standpoint, you can use a common collection for all device data for all users or common collections (one per device type) depending your use case, and then make the collection(s) private so that a user will be able to see and modify only his data.


Let me get another set of eyes to look at this in case I have missed something.



Regards,

Wani


1 person likes this
Thanks Wani, I'm working on an IoT startup so the users would have multiple devices sending small amount of data when an event happens. I'm hoping to have hundreds and eventually thousands of users, but realistically it won't be high in the beginning. Do you know what BL API call I would use to create a collection? I didn't see it in the reference section. Also, do you know why Kinvey doesn't recommend it? I was thinking security-wise it would be better to keep the user data separate. Also, it might be quicker since it won't be looking through everyone's data.

Hi Oliver,


You can do this by setting up onPostSave BL for users.


While Kinvey doesn't specifically restrict this, I wouldn't recommend it.


Can you tell me more about the use case? And also the number of users, size of data per user etc.


Regards,

Wani

Login or Signup to post a comment