OrientDB服务器错误

时间:2016-04-28 15:22:09

标签: orientdb orientjs

我遇到了orientjs驱动程序(https://github.com/orientechnologies/orientjs)或我的OrientDB(v2.1.15)的问题。我有一个Node.js服务器并打开与数据库服务器的连接,如下所示:

var OrientDB = require('orientjs');
var orientserver = OrientDB({
    host: 'localhost',
    port: 2424,
    username: 'root',
    password: 'Orientdb'
});

接下来我打开一个数据库连接并使用这个数据库,到目前为止一切正常。但是,如果我想用orientserver.list()方法列出所有数据库,我会收到此错误:

Unhandled rejection OrientDB.RequestError: Server user not authenticated.
at Operation.parseError (/home/mklaus/IdeaProjects/Thesis/node_modules/orientjs/lib/transport/binary/protocol28/operation.js:855:13)
at Operation.consume (/home/mklaus/IdeaProjects/Thesis/node_modules/orientjs/lib/transport/binary/protocol28/operation.js:446:35)
at Connection.process (/home/mklaus/IdeaProjects/Thesis/node_modules/orientjs/lib/transport/binary/connection.js:383:17)
at Connection.handleSocketData (/home/mklaus/IdeaProjects/Thesis/node_modules/orientjs/lib/transport/binary/connection.js:284:17)
at emitOne (events.js:90:13)
at Socket.emit (events.js:182:7)
at readableAddChunk (_stream_readable.js:147:16)
at Socket.Readable.push (_stream_readable.js:111:10)
at TCP.onread (net.js:525:20)

要找到问题,我在此时记录了我的服务器并获取:

Server {
  useToken: false,
  logger: 
   { error: [Function: bound bound ],
     log: [Function: bound bound ],
     debug: [Function] },
  transport: 
   BinaryTransport {
     domain: null,
     _events: { reset: [Function: bound ] },
     _eventsCount: 1,
     _maxListeners: Infinity,
     connecting: 
      Promise {
        _bitField: 268566529,
        _fulfillmentHandler0: undefined,
        _rejectionHandler0: undefined,
        _progressHandler0: undefined,
        _promise0: undefined,
        _receiver0: undefined,
        _settledValue: [Circular],
        _boundTo: [Circular] },
     closing: false,
     retries: 0,
     maxRetries: 5,
     host: 'localhost',
     port: 2424,
     username: 'admin',
     password: 'admin',
     servers: [ [Object] ],
     currentServer: 0,
     enableRIDBags: true,
     useToken: false,
     token: <Buffer >,
     sessionId: 62,
     logger: 
      { error: [Function: bound bound ],
        log: [Function: bound bound ],
        debug: [Function] },
     connection: 
      Connection {
        domain: null,
        _events: [Object],
        _eventsCount: 3,
        _maxListeners: Infinity,
        host: 'localhost',
        port: 2424,
        socket: [Object],
        logger: [Object],
        enableRIDBags: true,
        closing: false,
        reconnectNow: false,
        protocol: [Object],
        queue: [],
        writes: [],
        remaining: null,
        connecting: false,
        protocolVersion: 32 },
     skipServerConnect: true },
  config: 
   { get: [Function: bound ],
     set: [Function: bound ],
     list: [Function: bound ] },
  domain: null,
  _events: 
   { reset: 
      [ [Function: bound ],
        [Function: bound ],
        [Function: bound ],
        [Function: bound ],
        [Function: bound ] ],
     error: [ [Object], [Object] ] },
  _eventsCount: 2,
  _maxListeners: Infinity }

如您所见,用户名和密码错误。有人知道为什么会这样吗?为什么我在使用一个数据库后无法访问服务器?

*编辑 这是我的nodejs服务器的代码(不是所有的,只是重要的部分)

var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var stringify = require('json-stringify-safe');
var routes = require('./routes/index');
var users = require('./routes/users');

var passport = require('passport');
var expressSession = require('express-session');
var Strategy = require('passport-local').Strategy;

var users = {};
var databases = {};

var OrientDB = require('orientjs');

var orientserver = OrientDB({
    host: 'localhost',
    port: 2424,
    httpPort: 2480,
    username: 'root',
    password: 'Orientdb'
});
passport.use(new Strategy({
        usernameField: 'username',
        passwordField: 'password',
        passReqToCallback: true
    },
    function(req, username, password, cb) {
        var sessID = req.sessionID;
        var dbkey = username+"_"+req.params.database;
        if(dbkey in databases) {
        } else {
            databases[dbkey] = orientserver.use({
                name: req.params.database,
                username: username,
                password: password
            });
        }
        users[sessID]= {id: sessID, username: username, database: dbkey};
        return cb(null, users[sessID]);
    }));
    var app = express();

// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');

// uncomment after placing your favicon in /public
//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: false}));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));

app.use(expressSession({secret: 'mySecretKey', cookie: { maxAge: 60000 }}));
app.use(passport.initialize());
app.use(passport.session());

app.get('/', function (req, res) {

});

app.get('/getAllProjects', function(req, res) {

    //https://github.com/kriskowal/q
    orientserver.list()
        .then(function (dbs) {
            var json = [];
            dbs.forEach(function(value, index) {
                json.push({"name": value.name});
            });
            //console.log('There are ' + dbs.length + ' databases on the server.');
            res.status(200).send(json);
        });
});

app.post('/:database',
    passport.authenticate('local', { failureRedirect: '/' }),
    function(req, res) {
        res.redirect("/"+req.params.database);
    });

因此,当我向getAllProjects发送第二个请求时,我收到错误。

0 个答案:

没有答案