gremlin - 更新 gremlin-server 后的问题
问题描述
目前我正在使用janusgraph-0.2.0-hadoop2服务器并使用gremlin@2.6.0库进行查询
const Gremlin = require("gremlin");
const client = Gremlin.createClient(8182, "192.168.0.103");
function test(p){
client.execute(q, {}, (err, results) => {
if (err) {
console.error(err);
client.closeConnection();
}
else {
console.log(results);
client.closeConnection();
}
});
}
查询g.V().count()
结果是[ 12 ]
查询g.V().has('name', 'saturn').valueMap()
结果是[ { name: [ 'saturn' ], age: [ 10000 ] } ]
我同意
但是在将我的 janusgraph 更新到janusgraph-0.5.0-hadoop2服务器并使用相同的库gremlin@2.6.0
获取不同的数据
查询g.V().count()
结果是[ { '@type': 'g:Int64', '@value': 12 } ]
查询g.V().has('name', 'saturn').valueMap()
结果是
[
{ '@type': 'g:Map', '@value': [ 'name', [Object], 'age', [Object] ] }
]
将库更新到gremlin@3.4.6
const gremlin = require('gremlin');
const client = new gremlin.driver.Client('ws://192.168.0.106:8182/gremlin', { traversalSource: 'g' });
async function test(q){
const res = await client.submit(q, {});
console.log('res',res)
client.close();
}
test()
查询g.V().count()
结果是[ 12 ]
查询g.V().has('name', 'saturn').valueMap()
结果是[ Map { 'name' => [ 'saturn' ], 'age' => [ 10000 ] } ]
在Hashmap中获取数据 我想知道
1. Is it necessary to update gremlin library 3.4.6 getting correct result.
2. After updating to 3.4.6 get data in hashmap format, Means i want to know i am getting correct data or not.
3. I want data in object format but got in hashmap. I know i can convert to object but incase data is in nested hashmap, I dont want to repeat and convert it.
请给我建议
解决方案
我会说使用当前版本的 Janus Graph 是一个非常好的主意。请注意,您应该使用 Janus 图形附带的 Gremlin 库,而不是单独更新这些库。如您所见,最新的 Javascript/Node Gremlin 客户端确实返回 Map 类型。