I am building a cms where the site and pages are stored within mongo. I need to be able to create a new site using another site as a template.
For example:
Site A - news page and home page
Create a new site selecting site A as a template, this selects site A and then makes copies of each page site A owns and saves them under Site B
The result
Site A - news page and home page
Site B - news page and home page
Site B will be able to then use site A as a starting point to build there new site.
I am new to Mongo/mongoid so really would like some pointers about the best way to approach this.
Thanks
One way to organise the data is to use collections with the site ID as the namespace, giving you collections like:
To create a new site from an existing one, you would copy the relevant collections (possibly excluding
.usersfor example), changing the namespace. That is, copysite_a.pagestosite_c.pages. In the shell:Note that
site_ais not a database name, but the namespace of a collection.There is a limit to the number of collections you can have in a database that might be a problem if you’re hosting the CMS in the cloud for many customers. You could get around this by having different databases for different customers. You should read the documentation on this for more details.
Another way to do this is to put the site ID in each document and always filter for this in your queries. Then you would only have a few collections, for example:
With the documents in those collections having a
site_idfield:The copying would be similar to above (but with filters and updating the
site_idfield in the function). I think namespaces for collections is a neater approach however.