# Count - Query language

**URL:** <https://discuss.dgraph.io/t/count-query-language/9799>\
**Category:** Documentation\
**Created:** [August 28, 2020, 5:48pm UTC](https://discuss.dgraph.io/t/count-query-language/9799 "2020-08-28T17:48:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![diggy](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/diggy/32/3666_2.png) [@diggy](https://discuss.dgraph.io/u/diggy)\
**Post date:** [August 28, 2020, 5:48pm UTC](https://discuss.dgraph.io/t/count-query-language/9799/1 "2020-08-28T17:48:17Z")

</div>

```
{
  var(func: allofterms([email protected], "eat drink man woman")) {
    starring {
      actors as performance.actor {
        totalRoles as count(actor.film)
      }
    }
  }
  edmw(func: uid(actors), orderdesc: val(totalRoles)) {
    [email protected]
    [email protected]
    totalRoles : val(totalRoles)
  }
}
```

{ var(func: allofterms(name@en, "eat drink man woman")) { starring { actors as performance.actor { totalRoles as count(actor.film) } } } edmw(func: uid(actors), orderdesc: val(totalRoles)) { name@en name@zh totalRoles : val(totalRoles) } }

```
curl -H "Content-Type: application/graphql+-" localhost:8080/query -XPOST -d ' blahblah' | python -m json.tool | less
        
```

```
package main
import (
	"context"
	"flag"
	"fmt"
	"log"
    
	"github.com/dgraph-io/dgo/v2"
	"github.com/dgraph-io/dgo/v2/protos/api"
    
	"google.golang.org/grpc"
)
var (
	dgraph = flag.String("d", "127.0.0.1:9080", "Dgraph Alpha address")
)
func main() {
	flag.Parse()
	conn, err := grpc.Dial(*dgraph, grpc.WithInsecure())
	if err != nil {
		log.Fatal(err)
	}
	defer conn.Close()
	dg := dgo.NewDgraphClient(api.NewDgraphClient(conn))
    
	resp, err := dg.NewTxn().Query(context.Background(), `blahblah`)
	
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("Response: %s\n", resp.Json)
}
```

```
import io.dgraph.DgraphClient;
import io.dgraph.DgraphGrpc;
import io.dgraph.DgraphGrpc.DgraphStub;
import io.dgraph.DgraphProto.Response;
import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;
import java.util.Map;
public class App {
    public static void main(final String[] args) {
        ManagedChannel channel =
            ManagedChannelBuilder.forAddress("localhost", 9080).usePlaintext(true).build();
        DgraphStub stub = DgraphGrpc.newStub(channel);
        DgraphClient dgraphClient = new DgraphClient(stub);
        String query = "blahblah";
    
        Response res = dgraphClient.newTransaction().query(query);
    
        System.out.printf("Response: %s", res.getJson().toStringUtf8());
    }
}

```

```
import pydgraph
import json
def main():
    client_stub = pydgraph.DgraphClientStub("localhost:9080")
    client = pydgraph.DgraphClient(client_stub)
    query = """blahblah"""
    res = client.txn(read_only=True).query(query)
    print('Response: {}'.format(json.loads(res.json)))
    client_stub.close()
if __name__ == ' __main__':
    try:
        main()
    except Exception as e:
        print('Error: {}'.format(e))

```

```
const dgraph = require("dgraph-js");
const grpc = require("grpc");
async function main() {
  const clientStub = new dgraph.DgraphClientStub("localhost:9080", grpc.credentials.createInsecure());
  const dgraphClient = new dgraph.DgraphClient(clientStub);
  const query = `blahblah`;
  const response = await dgraphClient.newTxn().query(query);
  console.log("Response: ", JSON.stringify(response.getJson()));
  clientStub.close();
}
main().then().catch((e) => {
  console.log("ERROR: ", e);
});

```

```
const dgraph = require("dgraph-js-http");
async function main() {
  const clientStub = new dgraph.DgraphClientStub("http://localhost:8080");
  const dgraphClient = new dgraph.DgraphClient(clientStub);
  const query = `blahblah`;
  const response = await dgraphClient.newTxn().query(query);
  console.log("Response: ", JSON.stringify(response.data));
}
main().then().catch((e) => {
  console.log("ERROR: ", e);
});

```

* * *
This is a companion discussion topic for the original entry at [https://dgraph.io/docs/query-language/count/](https://dgraph.io/docs/query-language/count/)

---

<div class="post-metadata">

**Author:** ![kisinga](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/kisinga/32/4768_2.png) [@kisinga](https://discuss.dgraph.io/u/kisinga)\
**Post date:** [October 17, 2020, 10:47pm UTC](https://discuss.dgraph.io/t/count-query-language/9799/2 "2020-10-17T22:47:22Z")

</div>

Is there s performance penalty to using count as opposed to having a distributed counter for the said nodes?  
I’m new to dgraph and I’m not sure of how it works internally

---

<div class="post-metadata">

**Author:** ![chewxy](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/chewxy/32/4339_2.png) [@chewxy](https://discuss.dgraph.io/u/chewxy)\
**Post date:** [October 17, 2020, 11:20pm UTC](https://discuss.dgraph.io/t/count-query-language/9799/3 "2020-10-17T23:20:18Z")

</div>

Can you clarify? What do you mean by distributed counter

---

<div class="post-metadata">

**Author:** ![kisinga](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/kisinga/32/4768_2.png) [@kisinga](https://discuss.dgraph.io/u/kisinga)\
**Post date:** [October 17, 2020, 11:31pm UTC](https://discuss.dgraph.io/t/count-query-language/9799/4 "2020-10-17T23:31:59Z")

</div>

Thanks for the quick reply,  
An additional variable that tracks the actual number of nodes (albeit more complex to keep up to date)
