I have a question with the architectural ones. I create an application that collects a large amount of data from users and I have to save it somewhere. Saving all data from all users in one collection in mongodb very quickly will cause the allowable limit of 16MB of data in the collection to be reached. For this reason, I decided to create a new collection for each subsequent user of my application by creating a collection name like this:
const getCollectionName = (userId: string) => {
return `${COLLECTIONS.DATA}_${userId}`
}
await mongoDb.createCollection(getCollectionName(userId));
I took this idea from my experience in working with firebase, where we can easily manage sub-collections for a given collection.
And now I have a question, is it a good idea to create a new collection for each user of my application separately, or are there some inconveniences resulting from this way of storing data that I have no idea about?
CodePudding user response:
In MongoDB, the maximum BSON document size is 16 megabytes and not *collection. As far as sub-collection goes, you can have nested collections in MongoDB (similar to Firestore) but that counts towards the 16 MB doc size limit.
Also checkout:
Is it a good idea to create a new collection for each user of my application separately,
While you can do this, you'll have to create indexes for every collection whenever it is created. Storing data of all users in a single collection might be easier depending on the use case.