当我尝试使用 surrealdb.js 设置 surreal 时,我收到此错误 idk
import { Surreal } from 'surrealdb.js';
const db = new Surreal();
async function main() {
try {
// Connect to the database
await db.connect('http://127.0.0.1:8000/rpc', {
// Set the namespace and database for the connection
namespace: 'test',
database: 'test',
// Set the authentication details for the connection
auth: {
namespace: 'test',
database: 'test',
scope: 'user',
username: 'root',
password: 'root',
},
});
// Create a new person with a random id
const created = await db.create('person', {
title: 'Founder & CEO',
name: {
first: 'Tobie',
last: 'Morgan Hitchcock',
},
marketing: true,
identifier: Math.random().toString(36).substr(2, 10),
});
// Update a person record with a specific id
const updated = await db.merge('person:jaime', {
marketing: true,
});
// Select all people records
const people = await db.select('person');
// Perform a custom advanced query
const groups = await db.query(
'SELECT marketing, count() FROM type::table($tb) GROUP BY marketing',
{
tb: 'person',
}
);
} catch (e) {
console.error('ERROR', e);
}
}
main();
我尝试在端点的开头替换为 is,但效果不佳。我不知道为什么没有任何效果,我几乎尝试了所有方法,但似乎没有任何效果。
错误消息表明您的应用程序正在尝试连接到位于 127.0.0.1:8000 的服务器并收到 ECONNREFUSED 错误。这通常意味着该地址和端口上没有运行服务器。
要解决此问题,您需要确保 surrealdb.js 尝试连接的服务器正在运行。如果服务器应该在本地计算机上运行,请确保它已启动并侦听端口 8000。
尝试通过 CLI 或在 Surrealist 上使用
start 命令来设置连接