gpt4 book ai didi

node.js - OrientDB和NodeJS如何连接DB?

转载 作者:太空宇宙 更新时间:2023-11-03 22:54:21 25 4
gpt4 key购买 nike

我是 OrientDB 的新手,之前我使用过 mongoDB。我想知道如何与 OrientDB 创建连接。

我使用了下面的代码,但不像 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");
});

最佳答案

请注意,orientdb 已 fork 为 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 上运行。

关于node.js - OrientDB和NodeJS如何连接DB?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28067036/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com