How to query all predicates from one node by one predicate?

For example:
The node mutation:

{
  set {
      _:七小福 <出品时间> "1988年11月10日" .
      _:七小福 <类型> "动作" .

  }
}

Maybe I will forget all the predicate except one predicate:<类型>,so how to get all the predicate from this node by the predicate <类型>?

Hi @wwwjljj,

To get all predicates, you could use expand(_all_) . Note that to use expand, type system will have to be used. Also, to get the node using <类型> , the predicate <类型> will have to be indexed.

The query will then look something like this:

{
  get_all_predicates(func: eq(<类型>, "动作")) {
    expand(_all_)
  }
}

Related Documentation:
Type System: https://dgraph.io/docs/query-language/type-system/
Expand Predicate: https://dgraph.io/docs/master/query-language/expand-predicates/
Indexing: https://dgraph.io/docs/master/query-language/schema/#indexing

To get started, you may also see how these things could be used using the interactive Dgraph tour, A Tour of Dgraph

Is there any other method?
I cannot use Type because almost every node have different structure.
If I have to use Type, mabe I have make a singe Type fore every node. And there is about 4 million different node.
image

1 Like

the only same part for all node is two predicate: name and title .
Can I create a type schema only the two predicate and select all predicate by one predicate: name ?

You can create a generic Type and use the same one in all entities you have. If you don’t need the Type System in the usual way, you can use it as you wish.

I would recommend that you use generics but maybe break it in small chunks e.g:

type BasicL1 {
  name
  title
}

type BasicL2 {
  pred2
  pred3
  ...
}

type BasicL3 {
  pred22
  pred21
  ...
}

That way you can use like

{
  get_all_predicates(func: eq(<类型>, "动作")) {
    expand(BasicL1)
  }
}
{
  get_all_predicates(func: eq(<类型>, "动作")) {
    expand(BasicL1, BasicL2)
  }
}
{
  get_all_predicates(func: eq(<类型>, "动作")) {
    expand(BasicL1, BasicL2, BasicL3)
  }
}

Thank you very much for your detailed answers. :+1:t2:
But I try to find a easy way to get the data of the node without the schema which I will spend time on. The way in Neo4j:

Hi again,

hmm, not sure what you wanna mean. Are comparing Dgraph and Neo4j? and suggesting some change?

Dgraph and Neo4j are very different in several means. The only similarity is they both are a similar type of GraphDB(property graph). Any other characteristics that differentiate them are design choices made through time by the founder and community requests.

We have moved to a Typed Schema like a year+(? feels like) ago, it was a request from the community. So, since then, users are getting used to it. The Type Definition is mandatory.

So, about your main question on this topic and taking your contextual responses into account. I think that the Type System won’t fit perfectly, so you have to “cheat” it. The Expand All won’t work, so you have to use a “fake type” and use like I mentioned expand(FakeType). That way you will be able to see all predicates even if you don’t wanna set correctly all Types definitions.

Cheers.

Got it.
Thank you for giving answers all the time.
So Dgraph is like a SQL database in some way : if we want to use it , we’d beter to set Type schema first like things in SQL database, and then insert data,and query the data.

And another Question :
Can I make a super Type which contains all predicates? Then expand(all) will work for every query. And when querying, use a filter function to filter null predicate.

Is this a good method ? or This method have some disadvantage

Yes, that was my first suggestion, but I personally recommend that you use as small chunks.

Dgraph doesn’t have nullable predicates. You have empty (just a space like predicate: "") or not used ones. Empty or no used edges, doesn’t have any usage on DQL.

What I recommend is that, if your type gets huge like 100 predicates, break it into small chunks.