Get vertex with all predicates


#1

Apparently the simplest thing we could possibly need to do, is both not documented, and maybe is not even supported. We want to get all the data for a single user ID. Hard, right?

To get the expected output, I’m able to do:

g.V("uuid1")
.save("firstName", "firstName")
.save("lastName", "lastName")
.save("hasTitle", "hasTitle")
.save("worksFor", "worksFor")
.all();

This returns

{
	"result": [
		{
			"firstName": "Rob",
			"hasTitle": "Senior Software Engineer",
			"id": "uuid1",
			"lastName": "Christian",
			"worksFor": "uuid3"
		}
	]
}

But I don’t want to name every predicate explicitly, I want all predicates implicitly. So instead I expect something like this to work:

g.V('uuid1')
.saveAllOutPredicates()
.all();

I found g.V("uuid1").saveOutPredicates("predicate").all(), but this gives me a payload that I don’t know how to use.

{
	"result": [
		{
			"predicate": "worksFor",
			"id": "uuid1"
		},
		{
			"predicate": "hasTitle",
			"id": "uuid1"
		},
		{
			"predicate": "firstName",
			"id": "uuid1"
		},
		{
			"predicate": "lastName",
			"id": "uuid1"
		}
	]
}

I tried .forEach'ing over this, but I don’t know how to merge this into 1 result object for the starting vertex.


#2

Yet another attempt. sigh…

var person = g.V("uuid1");

person.outPredicates().forEach(function(d) {
  var res = {};
  res[d.id] = person.out(d.id).toValue();
  g.emit(res);
});

Result:

{
	"result": [
		{
			"worksFor": "uuid3"
		},
		{
			"hasTitle": "Senior Software Engineer"
		},
		{
			"firstName": "Rob"
		},
		{
			"lastName": "Christian"
		}
	]
}

#3

Got it!

var result = {};
var person = g.V("uuid1");

person.outPredicates().forEach(function(d) {
  result[d.id] = person.out(d.id).toValue();
});

g.emit(result);
{
	"result": [
		{
			"firstName": "Rob",
			"hasTitle": "Senior Software Engineer",
			"lastName": "Christian",
			"worksFor": "uuid3"
		}
	]
}

It’s hard to trust which parts of JS I can depend on, because arrow functions don’t seem valid.


FAQ: Frequently Asked Questions