Dgraph: Query for total number of nodes

Created on 11 Oct 2017  路  7Comments  路  Source: dgraph-io/dgraph

Lots of users have asked for this feature (or some variant of it). New users may get a bad impression of Dgraph since it cannot currently support 'basic' operations that other graph databases have. The answer that a 'count all nodes' function doesn't scale well may not be satisfactory for people who don't understand the technical details as to why this is the case.

One solution that @pawanrawal and I discussed:

  • Use the _predicate_ predicate to find all nodes. Then we can just return the count of those nodes.
kinfeature

Most helpful comment

This query gives you the total count of nodes in your data:

{
  total (func: has (_predicate_) ) {
    count(uid)
  }
} 

All 7 comments

Sounds good.

Current version is "v1.0.6", is this feature implemented or planned?

You should be able to run something like this to get the total number of nodes.

{ total(func: (has, "_predicate_") { count(uid) } }

@kdsgambhir : Can you test this, and document this in how to section?

This query gives you the total count of nodes in your data:

{
  total (func: has (_predicate_) ) {
    count(uid)
  }
} 

Being done in Ratel.

How is this done in v1.1? Since _predicate_ doesnt exist anymore.

You could assign all you nodes to a dummy type, and then run.

{
  total (func: eq (dgraph.type, DummyType) ) {
    count(uid)
  }
} 
Was this page helpful?
0 / 5 - 0 ratings

Related issues

mbudge picture mbudge  路  3Comments

pjebs picture pjebs  路  4Comments

armaneous picture armaneous  路  3Comments

janardhan1993 picture janardhan1993  路  3Comments

jerodsanto picture jerodsanto  路  3Comments