I am new to Dgraph and I am curious that how can I query some particular nodes in it?
Let me give you a example:
With MySQL
When using MySQL, I have saved a few records which we call them Department records who save some information for different dept(s).
id | dept_name | some_other_fields |
---|---|---|
1 | dept1 | blabla |
2 | dept2 | blabla |
3 | dept3 | blabla |
I can pick up these dept information easily with a SELECT statement.
With Dgraph
I am going to save these department as nodes(Please corrects me if I am using it wrongly):
{
set {
_:dept1 <name> "dept1" .
_:dept1 <some_other_predicate> "blabla" .
_:dept2 <name> "dept2" .
_:dept2 <some_other_predicate> "blabla" .
_:dept3 <name> "dept3" .
_:dept3 <some_other_predicate> "blabla" .
_:product1 <name> "product1" .
_:product1 <belong> _:dept1 .
}
}
And I am wondering: How can I query all the nodes from the database?
- If I use has(name) query, I will get all the nodes including the product which doesn’t meet my requirement.
- Of course I can use has(some_other_predicate) query to find the department just fine, but what if some other nodes save this predicate some_other_predicate in the future and it will come to the same dilemma again.
So, how can I query the department node properly and query it straight-forwardly?
What would be the best practice?