David Torres
David Torres

Reputation: 165

Gremlin groupCount() return only gt 2

I have the following Gremlin traversal, running on Azure CosmosDB, and I only want to return URLs with a count greater than 1. I'm not sure how to limit the return from the groupCount().

g.V().hasLabel('article').values('url').groupCount()

Upvotes: 3

Views: 2842

Answers (2)

David Torres
David Torres

Reputation: 165

Per my comment on the answer from Stephen Mallette, Azure CosmosDB Graph https://learn.microsoft.com/en-us/azure/cosmos-db/gremlin-support doesn't support the filter step so I used the where step to achieve the desired results.

g.V().hasLabel('article').groupCount().by('url').unfold().where(select(values).is(gt(1)))

Upvotes: 4

stephen mallette
stephen mallette

Reputation: 46206

Here's an example from the modern toy graph:

gremlin> g = TinkerFactory.createModern().traversal()
==>graphtraversalsource[tinkergraph[vertices:6 edges:6], standard]
gremlin> g.V().hasLabel('software').in().
......1>   groupCount().
......2>     by('name').
......3>   unfold().
......4>   filter(select(values).unfold().is(gt(1)))
==>josh=2

So you do the groupCount() and then unfold() the resulting Map then filter() the individual values from the Map.

In your case you would probably have something like:

g.V().hasLabel('article').
  groupCount()
    by('url').
  unfold().
  filter(select(values).unfold().is(gt(1)))

Upvotes: 6

Related Questions