Export mongodb query result to csv

1. Create a file “exportwords.js” and add following code: var today = new Date(); var year = today.getFullYear(); var month = today.getMonth(); var day = today.getDate(); var date = year + “-” + month + “-” + day; print(“Query”); db.searchwords.find({date: date}).forEach(function(sw){ print (sw.query); }) 2. Run following command: mongo databasename exportwords.js > exportwords.csv

Loopback : How to get the current user on loopback models

To get the current user add following code on server.js : app.use(function (req, res, next) { if (!req.accessToken) return next(); var userId = req.accessToken.userId; app.models.User.findById(userId, function(err, user) { if (err) return next(err); if (!user) return next(‘No user found!’); var loopbackContext = loopback.getCurrentContext(); if (loopbackContext) loopbackContext.set(‘currentUser’, user); next(); }); }); To get current user from model […]

Configure SELinux with semanage on Centos

You can manage your SELinux configuration on run time with “semanage” without rebooting the server.To install semanage you’ve install “policycoreutils-python” $ sudo yum -y install policycoreutils-python Permission for mongodb on port 27017 $ sudo semanage port -a -t mongod_port_t -p tcp 27017 For Http server SELinux policy make permissive $ sudo semanage permissive -a httpd_t