Compare predicates from two different nodes

I have two different nodes, first one is person {name, age}
and second one is family{ person_name }.

I want to query all families that match person_name with name in person node. How can I do it?

ex: person => [ {‘Alex’, 25} , {‘Bob’, 30}, {‘John’, 50} ], family=> [ {‘John’}, {‘Bob’}, {‘Test’} ].
So my query should print family => [ {'John'}, {'Bob'} ].

@pawan

Before anything, for you case maybe you could find some info here https://docs.dgraph.io/query-language#term-matching

The idea of having the first name inside the node “family”, does not make much sense to me. Could you elaborate? If a family has multiple “Bob” how you can keep each “Bob” unique? You should create a “tree” for it oO. It is better that there is a family name then you filter by the family name you want to find.

About Var Blocks https://docs.dgraph.io/query-language/#var-blocks
About Reverse Edges https://docs.dgraph.io/query-language#reverse-edges

In that case to see what family the user is. You need to put family as “@reverse”. If the family has to be unique, you must give a single markup for each or “save/collect/keep” your UIDs in another way.

Can you try this?

{
  var(func: has(family)) {
    family  @filter(allofterms(name@en, "Bennett Russell Diaz"))  {
      ~family  {
        myVar AS uid
      }
    }
  }
  
   userWithfamily(func: uid(myVar), orderasc: name) {
    name@en
    age
    family { 
      family_name
    }
  }

}

@MichelDiz I was thinking about allofterms. In my case I have two not connected nodes with different predicates. I like your query. But this is not what is was looking for.
Example: logging_status has logger_name string predicate.

{
  query(func: has(logging_status)) 
  {
      logger_name // 'john' , 'mike', 'jacho' <= i need to save this result as a variable ex: logger_name_results,
  }

  query2(func: has(loggers)) @filter(allofterms(name, logger_name_results) ) 
  {
     expand(_all_)
  }
}

So I need to get all names from logging_status and check if loggers name matches one of the logging_status logger_name, if they match return all.
Any ideas how to do it?

I still do not understand your purpose. It’s clear what it says, but for me it’s vague when what the Dgraph can do for you. In Dgraph there is no comparison of strings as far as I know (except for password comparison https://docs.dgraph.io/query-language/#extended-types). You can make two query blocks and then compare in your application. I think that would be the most Dgraph could do for you on this issue.

This your sample query may work, but it is not accurate as to the user’s identity. Having said that, I do not understand the intent.

@omurbekjk all identification needs to be unique. That way either you need to create your aproach in your bussines-logic(aplication layer) or you use the Dgraph functionality in connecting nodes trought UID.

For example, you will aways have more than one John. Soon that identification you need to compare needs to be unique.

Instead of sending “john” you could send the UID of John’s node. Since it seems to me that in this last query you want to queue. A queue of logged users right?

One note, in your query you are using two query blocks. The first must be “var” to be a variable block.

I’m not sure if this query below can work. I did not test it.


{
  var(func: has (logging_status))
  {
      n_Results AS logger_name
  }

  query (func: has (loggers)) @filter (allofterms (name, n_Results))
  {
     expand (_all_)
  }
}
1 Like

Try https://docs.dgraph.io/query-language#inequality

eq(predicate, [val1, val2, …, valN])

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.