这是企业项目的一部分。我正在尝试在我公司建立的 stackato 服务器上托管一个应用程序。我的应用程序有一个支持 mongodb 的节点框架。我编写了一个简单的脚本来尝试连接到 db 服务并插入一个 JSON 对象。我能够成功连接到数据库,但在插入时,返回错误消息:
MongoError:未授权在 db:componentlist 上插入
我的代码:
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();
});
});
});
当我在安装了 node 和 mongodb 的机器上运行它时,终端会返回这个。这些是一组可以与代码相关的控制台日志消息
连接到在线数据库,现在将数据存储在:db,数据库已打开。,无法将对象插入组件列表 MongoError:未授权在 db.componentlist 上插入
我在网上查了db,再次确认没有数据插入成功。我是否缺少任何额外的授权命令?