Databases - NGRP/node-red-viseo-bot GitHub Wiki
The VISEO Bot Maker provides connection to NoSQL (NeDB, MongoDB, CosmosDB).
MongoDB
Install MongoDB
The documentation to install Ubuntu is here
By default, MongoDB can only be reached as localhost. If running MongoDb on a different server, allow external connection as explained below:
Allow external connection
On the MongoDB server, edit /etc/mongod.conf
net:
port: 27017
bindIp: 127.0.0.1,[mongodb ip]
mongodb ip is the IP of the MongoDB server, not the IP of the servers which use MongoDB.
Database users
In mongo shell, create your admin user as well as an applicative user with restricted access rights.
You can create your mongo shell script with the content below:
loginAdmin = "your-admin";
passwordAdmin = "admin-password";
loginUser = "your-application-user";
passwordUser = "user-password";
database = "your-database";
db = connect("localhost:27017/admin");
if(db.system.users.find({user: loginAdmin}).count() === 0) {
db.createUser(
{
user: loginAdmin,
pwd: passwordAdmin,
roles: [ "root" ]
}
);
}
db = db.getSiblingDB(database);
try {
if(db.system.users.find({user: loginUser}).count() === 0) {
db.createUser({
user: loginUser,
pwd: passwordUser,
roles: [ { role: "readWrite", db: database } ]
});
} else {
db.grantRolesToUser(loginUser, [{ role: "readWrite", db: database }]);
}
} catch(err) {
print(err);
}
If your MongoDB is on a distant server, you can run your script as such:
mongo [ip]:[port]/admin myscript.js
Enable security
Once you have created your users you should enable security.
It is highly recommended if you have allowed external connections. On the MongoDB server, edit /etc/mongod.conf
security:
authorization: enabled
Collection indexes
To better your performances, create your indexes
In mongo shell it goes like this:
db.createCollection('collection');
db.collection.createIndex( { field: 1 }, { unique: false } );