2015-01-21 57 views
1

我是OrientDB中的新成員,之前我使用過mongoDB。我想知道如何與OrientDB建立連接。OrientDB和NodeJS如何連接DB?

我使用下面的代碼,但不像MongoDB那樣工作。我還想打印打印我的端口號在哪裏我的應用程序運行,如:「偵聽端口6060」

var orientdb = require('orientdb'); 

var dbConfig = { 
    user_name: "root", 
    user_password: "root" 
}; 
var serverConfig = { 
    host: "localhost", 
    port: 2480  //server port Number 
}; 

console.log(orientdb) 

var server = new orientdb.Server(serverConfig); 

var db = new orientdb.Db("remote:localhost/Gunjan", server, dbConfig); 
         //I also used 'Gunjan' only here. 
db.open(function(err) { 
    if (err) { 
     throw err; 
    } 
    console.log("Successfully connected to OrientDB"); 
}); 

回答

4

注意,orientdb被分叉成oriento,這是維持。

例子:

var Oriento = require('oriento'); 

var server = Oriento({ 
    host: 'localhost', 
    port: 2424, 
    username: 'root', 
    password: 'yourpassword' 
}); 

// List databases 
server.list().then(function (dbs) { 
    console.log('There are ' + dbs.length + ' databases on the server.'); 
}); 

請注意,您必須有OrientDB服務器上運行localhost:2424

+0

我面臨這些錯誤:可能未處理OrientDB.ConnectionError [0]:套接字已關閉。 – higunjan 2015-01-21 12:49:23

+0

我使用了錯誤的端口號2480.它是2424 可以問我如何查看我的服務器端口號? – higunjan 2015-01-21 13:15:35

+1

@GunjanPatel可能是配置中的可配置字段。 – 2015-01-21 16:42:24