gpt4 book ai didi

node.js - 如何获取仅包含数据的node-neo4j返回 Node

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

我正在使用node-neo4j连接到neo4j图形数据库。我注意到,每当我尝试获取所有 Node (例如用户)时,返回的 json 结果都会包含太多我不需要的信息。

这是返回所有用户 Node 的代码:

User.getAll = function (callback) {
var query = [
'MATCH (user:User)',
'RETURN user',
].join('\n');

db.query(query, null, function (err, results) {
if (err) return callback(err);
var users = results.map(function (result) {
return new User(result['user']);
});
callback(null, users);
});
};

它给了我这些 json 响应;

[
{
"_node": {
"_nodeNeo4j": {
"version": "1.1.0",
"constructor": "Node"
},
"_data": {
"extensions": {},
"outgoing_relationships": "http://localhost:7474/db/data/node/13/relationships/out",
"labels": "http://localhost:7474/db/data/node/13/labels",
"all_typed_relationships": "http://localhost:7474/db/data/node/13/relationships/all/{-list|&|types}",
"traverse": "http://localhost:7474/db/data/node/13/traverse/{returnType}",
"self": "http://localhost:7474/db/data/node/13",
"property": "http://localhost:7474/db/data/node/13/properties/{key}",
"properties": "http://localhost:7474/db/data/node/13/properties",
"outgoing_typed_relationships": "http://localhost:7474/db/data/node/13/relationships/out/{-list|&|types}",
"incoming_relationships": "http://localhost:7474/db/data/node/13/relationships/in",
"create_relationship": "http://localhost:7474/db/data/node/13/relationships",
"paged_traverse": "http://localhost:7474/db/data/node/13/paged/traverse/{returnType}{?pageSize,leaseTime}",
"all_relationships": "http://localhost:7474/db/data/node/13/relationships/all",
"incoming_typed_relationships": "http://localhost:7474/db/data/node/13/relationships/in/{-list|&|types}",
"data": {
"uid": "53c7a820-f0b4-11e3-af63-28373723792e",
"name": "user1"
}
}
}
},

有没有办法只返回密码结果的“数据”部分?或者我应该在将结果返回给客户端之前去除node.js服务器中不需要的部分?

谢谢!

最佳答案

通过更改返回的响应,我设法仅返回数据字段

User.getAll = function (callback) {
var query = [
'MATCH (user:User)',
'RETURN user',
].join('\n');

db.query(query, null, function (err, results) {
if (err) return callback(err);
var users = results.map(function (result) {
return new User(result['user']['data']);
});
callback(null, users);
});
};

我更改了return new User(result['user']['data']),它成功返回了响应的“数据”部分。

关于node.js - 如何获取仅包含数据的node-neo4j返回 Node ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24147015/

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