MangoDB, database technologies can't get simpler.
Welcome to your shiny new MangoDB instance! Till we get the CLI up and running feel free to stop by here to learn how to operate your database.
Video Crash Course: Currently Unavailable.
Just clone the branch (with and without backup) you want from our GitHub repo or dowload it from the MangoDB repository. We recommend the the starter with backup template if you intend to deploy your database instance.
git clone -b <branch name> https://github.com/webdevsint/mango-starter.git
Extract the zip if you downloaded it. Navigate to the directory. Open up a terminal and type the following command:
npm install --save
We're not done just yet. Lastly you need to set some environment variables or secrets in the "./.env" file we provided. You can find it in the root of your installation folder. Open it in any text editor an populate the empty fields. The URI field is your repository link with a Personal Access Token which is used to make instance backups. eg.
API_KEY="12345"
KEY="lorem ipsum"
NAME="Tahmid Jaglul"
MAIL="tahmid@amogus.org"
URI="https://this-is-my-token@github.com/projectbasic/backup.git"
And done!
Note: Make sure your secret values are secure. Do not share them to anyone. Please don't change the "KEY" secret if you have any documents. Doing so will make those documents inaccessible without the original key.
To define the properties of your document objects head over to the "./documents/" folder in the root of your installation. Open up the "./params.js" file in any text editor and you will fined an empty array called params.
const params = [];
Populate this array with the properties you want each of your document entries to have and save the file. eg.
const params = ["name", "hobby"];
Now after adding your properties, open up a terminal in the "./routes/" folder and type the following command:
node set
Your database is now configured to be used.
To create a new document head over to the "./documents" folder in the root of your your installation folder. Open up a terminal and and type the following command:
node new <name>
Here, <name> is just a placeholder. Replace it with what name your document should be. If the server is running, restart it.
To Delete any document head over to the "./documents" folder in the root of your your installation folder. Open up a terminal and and type the following command:
node delete <name>
MangoDB instances can be safely backed up to GitHub via Personal Access Tokens. Such state backups are made automatically after each entry is added. You need to add your Personal Access Token as an environment variable as illustrated above. Documentation on how to generate a token:
Creating a personal access token - GitHub Docs
After generating your token, go to GitHub and create a private repository. Let's say you named it "backups". Now we need to form your access URI, which will be like:
https://<token>@github.com/<username>/<repository>.git
For example:
https://this-is-my-token@github.com/projectbasic/backup.git
Now add this link as an environment variable. Now you're good to go!
Navigate to your your installation folder. Open up a terminal and and type the following command:
npm run start
Your database's API should serve on http://localhost:3000.
URL structure of the database (example): http://localhost:3000/?api_key=12345&document=Test
To add a new entry document entry just send a POST request to the "/" endpoint (ensuring the proper URL structure) with an object in the body containing your entry. eg.
Endpoint used here:
http://localhost:3000/?api_key=12345&document=Test&index=0
POST
The object must have the same properties as the ones you set for your documents here.
Similarly, to delete document entries just send a DELETE request request to the "/" endpoint (ensuring the proper URL structure) with an additional query parameter "index" with the index of the entry you want to delete from the document. eg.
Endpoint used here:
http://localhost:3000/?api_key=12345&document=Test&index=0
DELETE
We used reqbin in our examples to send requests to the API.
We tested and recommend using Replit.com to host your database instances. Here is a step by step guide on how you can do so:
Note: We recommend using the state backup for deployment as Replit may restart your repl since it isn't paid and you may lose some data.
Firstly login to Replit or signup if you don't have an account already, it's free. After logging in you will be redirected to the dashboard. You will find a "Create Repl" on the top left corner of the page.
You can deploy a starter template on the cloud by following the installation steps on the Repl's terminal instead of your own hardware. Additionally you will need to create the ".replit" file too following Step 3.
Step 1: Click on the New Repl and you'll and the "Create a repl" interface should pop up. Select Node.js as your template and name it whatever you want. We'll be naming it "Test" here.
We are redirected to our repl (https://replit.com/@username/Test) and we are get this screen:
Step 2: Go ahead and delete that "./index.js" file.
Step 3: Create a new file called ".replit" and just paste these contents in it and it will automatically save in a few moments:
language = "nodejs"
run = "npm run start"
Step 4: Now just upload all the instance files from your local machine and click on the Run button and your database should be up and running on the cloud. You can now not only serve your data but also add and delete entries on the cloud. For best performance add an UptimeRobot monitor to make your Repl always run.
Note: This product is constantly under development and a CLI is incoming. Enjoy your stay with us.
Thank you for trying out our product!
For contributions or queries, contact: nehan.khan779@gmail.com
© The Basic Team 2021