# Have many \`schema\`s

**URL:** <https://discuss.dgraph.io/t/have-many-schema-s/2822>\
**Category:** Dgraph\
**Created:** [June 28, 2018, 8:34am UTC](https://discuss.dgraph.io/t/have-many-schema-s/2822 "2018-06-28T08:34:10Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![srinathganesh](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/srinathganesh/32/896_2.png) [@srinathganesh](https://discuss.dgraph.io/u/srinathganesh)\
**Post date:** [June 28, 2018, 8:34am UTC](https://discuss.dgraph.io/t/have-many-schema-s/2822/1 "2018-06-28T08:34:10Z")

</div>

I wanted to try out Node types and got this documentation [https://docs.dgraph.io/howto/#giving-nodes-a-type](https://docs.dgraph.io/howto/#giving-nodes-a-type)

And ended up with this Python code that seems to work.

```auto
import pydgraph
import json

client_stub = pydgraph.DgraphClientStub('localhost:9080')
client = pydgraph.DgraphClient(client_stub)

# Create Schema
schema = """type: string @index(exact) .
            name: string ."""
op = pydgraph.Operation(schema=schema)
client.alter(op)

# Data
txn = client.txn()
p = {
    "type": "People",
    "name": "Alpha",
}
assigned = txn.mutate(set_obj=p)

q = {
    "type": "People",
    "name": "Beta",
}
assigned = txn.mutate(set_obj=q)
txn.commit()

# Fetch type people
# Fetch Data
query = """query all($a: string) {
    all(func: eq(type, $a)) {
        expand(_all_) {}
    }
}"""
variables = {'$a': 'People'}

# Print
res = client.query(query, variables=variables)
ppls = json.loads(res.json.decode('utf-8'))

for ppl in ppls["all"]:
    print(ppl)

```

But I want to have isolated/different `Schema` for different node types, with different properties. (ie. instead of one big schema with 1000 properties, have 100 separate schema with 10 properties each)

I saw this post, but didn’t find a working sample [Dgraph schema system - #5 by ashwin95r](http://discuss.hypermode.com/t/dgraph-schema-system/916/5)

---

<div class="post-metadata">

**Author:** ![rgupta](https://avatars.discourse-cdn.com/v4/letter/r/85f322/32.png) [@rgupta](https://discuss.dgraph.io/u/rgupta)\
**Post date:** [June 28, 2018, 8:44am UTC](https://discuss.dgraph.io/t/have-many-schema-s/2822/2 "2018-06-28T08:44:22Z")

</div>

I also have same question [here](http://discuss.hypermode.com/t/how-many-schema-can-we-have-in-one-dgraph/2821)

---

<div class="post-metadata">

**Author:** ![MichelDiz](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/micheldiz/32/11873_2.png) [@MichelDiz](https://discuss.dgraph.io/u/MichelDiz)\
**Post date:** [June 28, 2018, 2:17pm UTC](https://discuss.dgraph.io/t/have-many-schema-s/2822/3 "2018-06-28T14:17:56Z")

</div>

This separation does not exist. Generally many nodes share the same predicate. E.g: `Name`.  
If you want extraordinarily separate you can create specific predicates like:

```auto
name.user
name.post
name.board

```

> [@srinathganesh](#):
>
> documentation [Get started with Dgraph](https://docs.dgraph.io/howto/#giving-nodes-a-type)

your code is different from the one shown in the documentation. The documentation approach is about giving nodes types via unique predicates. And not a single predicate named “Type” indexed. This is another possible approach, but not specifically recommended.

In the case of the recommended approach your code should look like this:

```auto

p = {
    "_People": "*",
    "name": "Alpha",
}

```

And your query:

```auto
{
  q(func: has(_People)) {
  uid
  expand(_all_)
  }
}

```

---

<div class="post-metadata">

**Author:** ![rgupta](https://avatars.discourse-cdn.com/v4/letter/r/85f322/32.png) [@rgupta](https://discuss.dgraph.io/u/rgupta)\
**Post date:** [June 29, 2018, 6:55am UTC](https://discuss.dgraph.io/t/have-many-schema-s/2822/4 "2018-06-29T06:55:46Z")

</div>

> [@MichelDiz](#):
>
> p = {  
> “\_People”: “\*”,  
> “name”: “Alpha”,  
> }

If i have more then 10 node types, then how we get the list of distinct node type?

---

<div class="post-metadata">

**Author:** ![MichelDiz](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/micheldiz/32/11873_2.png) [@MichelDiz](https://discuss.dgraph.io/u/MichelDiz)\
**Post date:** [June 29, 2018, 3:44pm UTC](https://discuss.dgraph.io/t/have-many-schema-s/2822/5 "2018-06-29T15:44:53Z")

</div>

Usually you create a pattern of Kinds. You can query for predicates like this:  
`schema {}`

or use Ratel and filter by the pattern you used.

Let’s say that your Kinds pattern starts with `has (type_person)`  
In Ratel you would write in the filter “type\_” and a list of predicates would appear with

```auto
type_person
type_board
type_document

```

---

<div class="post-metadata">

**Author:** ![rgupta](https://avatars.discourse-cdn.com/v4/letter/r/85f322/32.png) [@rgupta](https://discuss.dgraph.io/u/rgupta)\
**Post date:** [June 30, 2018, 3:38am UTC](https://discuss.dgraph.io/t/have-many-schema-s/2822/6 "2018-06-30T03:38:17Z")

</div>

thank you, if this was documented in a tutorial it would have been much better
