2016-11-07 69 views
3

如何使用connect-orientdb模塊我的目標是將我的服務器代碼與nodejs和expressjs框架連接到我的orientdb數據庫。首先,我想將我的會話存儲在數據庫中。但是我很難將我的服務器連接到數據庫。如何使用express-

當我執行server.js我得到的錯誤:

/Users/soroush/Desktop/nodeOrient/node_modules/connect-orientdb/lib/connect-orientdb.coffee:191 
    })(connect.session.Store); 
        ^

TypeError: Cannot read property 'Store' of undefined 
    at module.exports (/Users/soroush/Desktop/nodeOrient/node_modules/connect-orientdb/lib/connect-orientdb.coffee:22:46) 
    at Object.<anonymous> (/Users/soroush/Desktop/nodeOrient/server.js:8:48) 
    at Module._compile (module.js:541:32) 
    at Object.Module._extensions..js (module.js:550:10) 
    at Module.load (module.js:458:32) 
    at tryModuleLoad (module.js:417:12) 
    at Function.Module._load (module.js:409:3) 
    at Function.Module.runMain (module.js:575:10) 
    at startup (node.js:160:18) 
    at node.js:449:3 

和我server.js代碼是:是,使用

var express = require('express'), 
    cs = require("coffee-script/register"), 
    app = express(), 
    path = require('path'), 
    cookieParser = require('cookie-parser'), 
    session = require('express-session'), 
    config = require('./config/config.js'), 
    orientDBStore = require('connect-orientdb')(session), 
    OrientDB = require('orientjs'), 
    orientDBConfig = { 
     server : { 
      host: "localhost", 
      port:2424 
     }, 
     db : { 
      user_name: "admin", 
      user_password: "admin" 
     }, 
     database : "sessions", 
     class_name : "sessions_class" 
    }, 
    server = OrientDB({ 
    hose : "localhost", 
    port : "2424", 
    username : "root", 
    password : "root" 
    }) 
    ; 

app.set('views', path.join(__dirname, 'views')); 
app.engine('html', require('hogan-express')); 
app.set('view engine', 'html'); 
app.use(express.static(path.join(__dirname,'public'))); 

app.use(cookieParser()); 

require('./routes/route.js')(express, app); 

    app.use(session({ 
     secret:"mySecret", 
     store: new orientDBStore(orientDBConfig) 
    })); 

app.listen(8000, function() { 
    console.log("app is listening on port 8000"); 
}) 

我的主要問題中的連接orientdb當會話模塊內置快速,但現在該會話是一個不同的模塊,我遇到了這個問題。

+0

看起來像你的價值與'商店'屬性是未定義的。 –

+0

@ OleksandrGubchenko是的,這就是問題,但我檢查了其他數據庫,如mongoDB,他們使用這種方法,並沒有這個問題。商店屬性在connect-mongodb模塊中定義。 – soroush

回答

0

終於讓我找到一個解決方案,如果任何人都面臨這樣的問題:

var session = require('express-session'), 
    OrientoStore = require('connect-oriento')(session); 

app.use(session({ 
     secret: 'SomeSecret', 
     store: new OrientoStore({ 
      server: "host=localhost&port=2424&username=dev&password=dev&db=test" 
     }) 
    })); 

更多信息這github link是有用。

0

查看OrientDB中的ExpressJS指南:Blog Tutorial with ExpressJS and OrientDB

而且try to use

orientDBStore = require('orient')(session), 

代替:

orientDBStore = require('connect-orientdb')(session), 
+0

東方是一個不同的模塊,我使用這個[link:npmjs.com](https://www.npmjs.com/package/connect-orientdb)來使用connect-orientdb模塊,但是有一些改變,現在會話模塊不是expressjs中的內置模塊,我已經單獨要求它。 – soroush

+0

我的主要問題是connect-orientdb在會話模塊內置express時使用,但現在該會話是我遇到此問題的另一個模塊。 – soroush

+1

它不是官方模塊,所以它可能已經過時 –

相關問題