This project is a three tier application having presentation, business logic and data layers. We used AngularJS for user interface and Node.js for business logic (accessing data) and multiple NoSQL databases for data storage. Our goal is to have a common user interface and an interoperable middle layer to access various NoSQL databases for performing simple CRUD operation. In the process, we were able to learn multiple NoSQL databases. We believe this work will be useful to others who are in need to explore NoSQL databases in a short period of time and hence we share our work here.
The following NoSQL databases are supported currently.
- MarkLogic 8
- Couchbase 4.5
- Redis 3.2.8
- MongoDB 3.4.1
- Microsoft Azure DocumentDB
- Google Cloud Datastore
- Amazon DynamoDB
Install/Register a NoSQL Database
Couchbase - Install and Start the server
Redis - Install and Start the server
MongoDB - Download
- Create a Google Cloud account - Free Trial(60 days/ $300 Credit)
- Create a Project
- Enable Datastore Google APIs
Requires configuration if there is a need for custom rest server and custom database.
- Create a Primary Index to use N1QL.
- Navigate to http://127.0.0.1:8091/ui/index.html#/query/workbench and execute the query on default bucket CREATE PRIMARY INDEX ON `default` USING GSI;
- After logging into the portal
- Click on NoSQL Database on the left menu
- Create account following this url - https://docs.microsoft.com/en-us/azure/documentdb/documentdb-create-account
- Enter ID(unique account string), Select DocumentDB, Free Trial, Create new for resource group(enter a name), and location as desired.
- Click on Create
No custom configuration is required
No custom configuration is required
- Create a service account
- Account Name : sample name
- Select a Role : Datastore > Datastore Owner
- Furnish a new private key : Select and keytype: JSON
- Click on Create button. This will download the .json key file
- Copy the downloaded json file to the project as /env/datastore.json
- Create a AWS account
- Create access key
-
Select Services -> IAM -> Users -> Add user
- Enter user name
- Select Access type for Programmatic access
- Create user and no need to specify persmissions and skip to complete page
- Download the .csv file
- Open the .csv file
- Copy the access key ID and secret access key to a file and the name the file as /home/user/.aws/credentials (for Mac) or c:\users\user\.aws\credentials as shown below:
aws_access_key_id = AKIAJJT7TPHFA4ALMAX aws_secret_access_key = O2z3Q/cEJSe8cmxf9uFIhK0yPC4McDSjiqgjdXDL
- Select Close
-
Select Services -> IAM -> Users
- Select the user link that you created and for which downloaded the access key file
- Select Permissions
- Select Add inline policy link
- Select Policy Generator and click Select
- Select/enter the following values
- Effect : Allow
- AWS Service : AWS DynamoDB
- Actitons : All Actions(*)
- ARN : *
- Select Add Statement
- Select Apply Policy
- Select/enter the following values
- Select Policy Generator and click Select
- Select Add inline policy link
-
env/marklogic-env.js has the following details. Update if different configuration is required
database: "Documents",
host: "localhost",
port: 8000,
user: "admin",
password: "admin",
authType: "DIGEST"
env/couchbase-env.js has the following details. Change the hostname or bucket name as required
cluster: "couchbase://localhost",
bucket: "default"
Update env/documentdb-env.js with the details configured on Azure. Details of the URI and Primary key can be found from keys page.
_config.host_ = process.env.HOST || "<URI>";
_config.authKey_ = process.env.AUTH_KEY || "<PRIMARY KEY>";
_config.databaseId_ = "documentdb456"; - Any database id can be specified, this will be created from the code
_config.collectionId_ = "tasks"; Any Collection id can be specified, this will created for the above databaseId from the code if it is not created already.
Once the database and collection are created, they can be found here
env/redis-env.js has the following details. Update if different configuration is required
host: "localhost",
port: 6379
_env/mongodb-env.js has the following details. Update if different configuration is required
host: "mongodb://localhost",
port: 27017,
database: "myproject"
Update env/datastore-env.js with the projectId from Google Cloud Console.
projectId: "sample-id",
kind : "Tasks"
Update _env/dynamodb-env.js with the endpoint information if you are using locally installed DynamoDB
- Run "npm install" on ang-node-nosql/
- Run "bower install" on ang-node-nosql/
- Run "npm install" on ang-node-nosql/client/
If there are changes to client, compile using "npm start" on ang-node-nosql/client/
-
To use MarkLogic as backend NoSQL database use the following command
node server --env MarkLogic
-
To use Couchbase as backend NoSQL database use the following command
node server --env Couchbase
-
To use DocumentDB as backend NoSQL database use the following command
node server --env DocumentDB
-
To use Redis as backend NoSQL database use the following command
node server --env Redis
-
To use MongoDB as backend NoSQL database use the following command
node server --env MongoDB
-
To use Google Cloud Datastore as backend NoSQL database use the following command
node server --env Datastore
-
To use Amazon DynamoDB as backend NoSQL database use the following command
_node server --env DynamoDB