Unable to reference existing nodes ( GO API )

Hello ! :grinning:
I’m creating a GO API that can handle http request to send query or mutations to my DgraphDatabase , so far so good , i can query and mutate from postman with no problems except that when i try to mutate to and existing node by referencing the uid from that node , it always creates a new node ( that doesn’t happen when i mutate in ratel ) and i’m having trouble finding what i did wrong.

Exemple : sending this in a POST request while uid:“0x131” exists in the DB


Returns this, And creates a new node named johnny with uid:“0x134”

txn:<start_ts:858 commit_ts:859 preds:"1-date_created" preds:"1-date_modified" preds:"1-firstname" > latency:<parsing_ns:68799 processing_ns:4069549 assign_timestamp_ns:1485334 5:5808062 > uids:<key:"dg.398602261.110" value:"0x134" > 

Here is how I setup my go Struct :

type Contact struct {
	uid            string       `json:"uid,omitempty`"
	FirstName      string       `json:"firstname,omitempty"`
	LastName       string       `json:"lastname,omitempty"`
	OfficePhone    string       `json:"officephone,omitempty"`
	Raw            []byte       `json:"raw_bytes,omitempty"`
	MobilePhone    string       `json:"mobilephone,omitempty"`
	Title          string       `json:"title,omitempty"`
	Department     string       `json:"department,omitempty"`
	PersonRole     string       `json:"role,omitempty"`
	PersonnalEmail string       `json:"personnalemail,omitempty"`
	City           string       `json:"city,omitempty"`
	Country        string       `json:"country,omitempty"`
	Address        string       `json:"address,omitempty"`
	Description    string       `json:"description,omitempty"`
	Dtype          []string     `json:"dgraph.type,omitempty"`
	Discussion     []Discussion `json:"disc,omitempty"`
	Email          []Email      `json:"email,omitempty"`
	Document       []Document   `json:"doc,omitempty"`
	AssignedTo     *AssignedTo  `json:"assignedto,omitempty"`
	BelongsTo      *BelongsTo   `json:"belongsto,string,omitempty"`
	CreatedBy    string    `json:"created_by,omitempty"`
	DateModified time.Time `json:"date_modified,omitempty"`
	DateCreated  time.Time `json:"date_created,omitempty"`

You need to use upper case UID in your type definition so that json marshaler can include it into the marshaled Json.

1 Like

Thanks for the quick reply ! I’m new to GO and i keep forgetting I have to use UpperCase in type declaration ( still used to the public / private ) , there also was a quote " missing in the json declaration that returned me an error.