Inserting nested child list with 2 or more columns without id


(James) #1

hi,

is it possible to insert a predicate that contains a list of data that contains multiple column?

example:

childField: [ { field1: "aa", field2: "bbb"} ]

i do not plan to insert the child fields as individual objects,

thank you


(Michel Conrado (Support Engineer)) #2

Nops, try something similar with Facets

https://docs.dgraph.io/query-language#facets-edge-attributes

Mutation

{
		"set": [
			{
				"childField": [ 
          {"column1": "This is a column",
    			 "column1|field1": "aa",
    			 "column1|field2": "aa2" },
          {"column2": "This is a column",
    			 "column2|field1": "bb" ,
    			 "column2|field2": "bb2" }
        ]
      }
		]
}

Query


{
  data(func: has(childField)){
    uid
    childField {
    uid
    column1 @facets
    column2 @facets
    }
  }
}

Response


{
  "data": {
    "data": [
      {
        "uid": "0x2711",
        "childField": [
          {
            "uid": "0x2712",
            "column1|field1": "aa",
            "column1|field2": "aa2",
            "column1": "This is a column"
          },
          {
            "uid": "0x2713",
            "column2|field1": "bb",
            "column2|field2": "bb2",
            "column2": "This is a column"
          }
        ]
      }
    ]
  }

(James) #3

thank you @MichelDiz

but this is hardcoding suffix of predicate with index of rows.
i did found out that facets only support specific name of predicate.

this is the only way todo it right? otherwise ive to work with uid


(Michel Conrado (Support Engineer)) #4

Not sure what you mean :confused:

btw another example would be the one below (Facets are like “list”)


{
		"set": [
			{
				"childField": [ {"childField|field1": "aa", "childField|field2": "aa" } ]
             }
 	        	]
}

There is no other way. Dgraph only accepts the specified Data types by design. There is no concept of “column” in a graph DB and there is no way to insert JSON obj into a predicate.