Apostrophe CMS running with Dynamo DB

2019-08-26 08:56发布

We would like to run Apostrophe in AWS, however our policy is to use Dynamo DB for our database needs. Is this possible?

On https://docs.apostrophecms.org/apostrophe/tutorials/intermediate/accessing-the-database-directly#making-your-own-database-connections

It says:

Maybe you don't even want to use MongoDB at all. That's okay. Nobody's stopping you from making your own database connection for your project-specific code.

I assume that means it is possible.

I have tried extending the apostrophe-db module to call

self.apos.db = new AWS.DynamoDB();

But the site won't initialise.

Can anyone who has attempted this please give some examples of how to do it if it is possible.

Thanks

1条回答
Bombasti
2楼-- · 2019-08-26 09:43

If you want to make the base Apostrophe-CMS modules use a database with a syntax other than MongoDB's, you'd be in for a lot of work. Unless I'm very much mistaken, Dynamo DB doesn't use the same query syntax as MongoDB. Apostrophe-CMS doesn't contain the ability to switch to other databases on the fly - you'd need to rewrite a lot of the code in a few Apostrophe modules in order to accomplish this, since Apostrophe is written to work with MongoDB. As an example, the apostrophe-docs module is what gives access to the documents collection that Apostrophe uses to store most of its data. You can see how the docs module is set up here: https://github.com/apostrophecms/apostrophe/blob/master/lib/modules/apostrophe-docs/lib/api.js

Notice how much of the code in that module is using a query syntax specific to MongoDB. Because of Apostrophe's wonderful inheritance system, it would probably be possible to overwrite every bit of code that Apostrophe uses to access MongoDB and replace it with code to access another database, but it would probably be an incredible amount of work.

The line you reference in your question seems to be referring to connecting to another database only inside of your custom modules. For example, if you want to create a Comments widget that pulls from a SQL database instead of from the Apostrope mongodb docs collection, you could pull in an NPM package like node-mssql and override lots of the default Apostrophe-CMS widget behavior inside of your Comments module. This would allow you to pull whatever data you'd like for that particular module, but Apostrophe would still need to be pulling data from its MongoDB instance.

查看更多
登录 后发表回答