Why am I using the @ id instruction but it is invalid during execution
dht-hedaihua opened this issue · comments
Question.
What I want to do
I want to use the @ id command as expected in the official document
What I did
add the @id tag in the schema,like below:
mobile_number: String! @id @search(by: [hash, regexp])
successfully executed the import of the schema,and the ‘mobile_number’ field has tagged ‘upsert’ in rateUI web.
I successfully added a node with ‘mobile_number’ attribute value. Then I tried to add another node with the same ‘mobile_number’ value as the previously added node. My expectation is that the dgraph should have reported an error, causing the addition to fail because I have already added the @ id tag to the ‘mobile_number’ field. However, it was successfully added. Now there are two nodes of the same type with the same ‘mobile_number’ value successfully in the library.
May I ask why this is? Is there something wrong with my operation or configuration? Thank you to any friend who can help me. Thank you!
Dgraph metadata
docker run dgraph/standalone and rateUI , the version is v23.0.0
the result json content is :
{
"data": {
"user_general_info": [
{
"uid": "0x4e23",
"User.mobile_number": "XXXXXXXXX",
"User.user_full_name": "hedaihua",
"User.gender": "",
"User.birthday": "0001-01-01T00:00:00Z",
"User.updated_at": "0001-01-01T00:00:00Z",
"User.created_at": "2023-07-16T09:00:31.0370496Z"
},
{
"uid": "0x4e24",
"User.mobile_number": "XXXXXXXXX",
"User.user_full_name": "hedaihua",
"User.gender": "",
"User.birthday": "0001-01-01T00:00:00Z",
"User.updated_at": "0001-01-01T00:00:00Z",
"User.created_at": "2023-07-16T09:04:13.7249037Z"
}
]
},
"extensions": {
"server_latency": {
"parsing_ns": 141903,
"processing_ns": 886312,
"encoding_ns": 69300,
"assign_timestamp_ns": 1234717,
"total_ns": 2441835
},
"txn": {
"start_ts": 20127
},
"metrics": {
"num_uids": {
"User.birthday": 2,
"User.created_at": 2,
"User.gender": 2,
"User.mobile_number": 2,
"User.updated_at": 2,
"User.user_full_name": 2,
"User.user_type": 2,
"_total": 16,
"uid": 2
}
}
}
}
I have used mutation addition in RateUI web and also added it using the official go client sdk. The results were all successfully added as described above. The key code added to used by go client sdk is as follows:
// do create
mu := &api.Mutation{
CommitNow: true,
}
pb, err := json.Marshal(ugi)
//error handle
mu.SetJson = pb
res, err := d.dTxn.Mutate(ctx, mu)
//error handle