This is a part of a corporate project. I am trying to host an application on the stackato server put up by my company. My app has a node framework with mongodb support. I wrote a simple script that tries to connect to the db service and insert a JSON object. I am able to successfully connect to the database but on inserting, returns an error saying:
MongoError: not authorized for insert on db:componentlist
My code:
var mongo = require('mongodb');
var Db = mongo.Db;
var Server = mongo.Server;
var services;
var dbcreds;
var dbcreds = {
//cant paste due to confidential reasons
};
var server = new Server(
dbcreds.host,
dbcreds.port,
{user: dbcreds.username, pass: dbcreds.password}
);
db = new Db(dbcreds.db, server,{w:1});
console.log('connecting to online db and now storing data in:' + dbcreds.db);
db.open(function(err, db) {
if (err) { console.log('db connection error: ' + err);}
console.log('db is opened.');
var component = [
{
platform: "alpha",
component1: "beta",
}];
db.collection('componentlist', function(err,collection){
collection.insert(component, function(err, result){
if(err){console.log("cannot insert the object into componentlist " + err);}
db.close();
});
});
});
The terminal returns this when I run this on my machine which has node and mongodb installed. These are a set of console log messages that you can relate to the code
connecting to online db and now storing data in:db, db is opened., cannot insert the object into componentlist MongoError: not authorized for insert on db.componentlist
I checked the db online to reconfirm that no data has been inserted successfully. Am I missing any extra authorization commands required?