I would like to know if I can allow end users of my app to define a schema and then create corresponding collection on the server.
I would then like to run code that finds all collections and creates an interface based on each collection’s schema.
Example:
My interface has a form to create a new interface.
User creates collection named “cow” with fields: race, weight, age.
Then I have something generic that finds that new collections among the list of collections (chickens and cows), and generates an interface accordingly for each one. The interface will be a create read update delete (CRUD) thing, generated for each collection.
I created an interface for a collection i already made, I want something that lets users create collections.
This is what I would like to do. Is it possible? Am I thinking of this in the wrong way?
A better model would be to have a collection “tables” for example with a user id. The a collection with “rows” or “documents” for the data. Every row contains the id of the table.
Can totally do it. I have a product totally based on user-defined Collections by submitting forms of schema, a cloud-based WYSIWYG table creator, and also supporting Autoforms
Our backend assumes user’s login name as the namespace prefix. All their created tables will have the prefix. Then at least their table names won’t clash each other.
And we are dealing with that limit by naturally limiting the number of tables they could create, according to the users’ plans they subscribed our SAAS.
yes, can you be a good solution. What I would be worried about is that indexes also count, so let’s say:
24.000 namespaces available
Let’s say 1 index per collection: So 12.000 collections possible.
Let’s say 10 collections per user: 1.200 users maximum.
It would worry me to follow that strategy because it’s about the max. In reality I would suppose it to be much lower when you also need indexes for performance.
Mongo sharding works on collection level. That means it can shard one collection over multiple servers by getting a shard key, for example userId. Which is a field in every document.
So no, even though the limit is removed now I don’t see a very good case for dynamically creating so many collections.
And since Meteor publications can query for the right data for this user I think it’s wiser to stay with one or a few collections. An alternative would be a database per user for the big ones.
A better model would be to have a collection “tables” for example with a user id. The a collection with “rows” or “documents” for the data. Every row contains the id of the table.
A better model would be to have a collection “tables” for example with a user id. The a collection with “rows” or “documents” for the data. Every row contains the id of the table.
How you could setup come collections, just a very rough idea:
I got it before then, what you mean is just putting a document inside a document. That probably has consequences for indexing and so.
Look at my other idea and tell which you think is better:
Since fields are not mandatory, I was thinking about just going for something like creating a collection for type_of_things and another collection for all_things
The type_of_things will describe what kind of things you can insert in all_things, and what type the fields are. From that I generate an interface for updating/creating.
And all_things has everything in it, but flat. And that generates the view/delete interface.
Only different is that I put the _id of the table in the row where you put a name (cow) in the all_things? If that’s your point I wouldn’t care, it will work both. I suppose that it’s easier to use an id but it is for no reason a requirement.
About the indexing: Rows._ensureIndex({ “name”: 1}); would do the trick. But you need to be a bit smart at which fields to index. It depends on which views you use, that’s quite easy to test.