You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am working with a microservice application where I need to get back the values for a record that I delete and using the "ReturnChanges" feature of rethink is perfect for this. It works for update and replace, but fails for delete.
resp, err = db.DB("content").Table("posts").Get(articleId).Delete(db.DeleteOpts{ReturnChanges: true}).Run(env.Session)
if err != nil {
fmt.Print(err)
return StatusError{500, err}
}
result , _ := resp.NextResponse()
spew.Dump(result)
deRefedJson := (*json.RawMessage)(&result)
spew.Dump(result)
var jsonResult interface{}
err = json.Unmarshal(*deRefedJson, &jsonResult)
spew.Dump(jsonResult)
var changes Changes
changes = jsonResult.(Changes)
The return values for the changes come as
{
"changes": {
{
"new_val": null,
"old_val": {
"author": "Christopher Stetson",
"date": {
"$reql_type$": "TIME",
"epoch_time": 1.527033878861e+09,
"timezone": "+00:00"
},
"location": "Oakland CA",
"title": "Test Post 1.4",
"album_id": 38,
"body": " This is the body",
"extract": "This is the extract",
"id": "b17caf88-c449-4e2a-8fee-f0e498f3d91c",
"photo": "http://fake-s3:4569/mra-images/uploads/photos/8abe3ad9-50d1-4c91-bbb7-6ca27fbad24c/medium.jpg"
}
}
},
"deleted": 1,
"errors": 0,
"inserted": 0,
"replaced": 0,
"skipped": 0,
"unchanged": 0
}
Where it should be returning the changes as an array:
"changes": [
{
"new_val": null,
"old_val": {
"author": "Christopher Stetson",
"date": {
"$reql_type$": "TIME",
"epoch_time": 1.527033878861e+09,
"timezone": "+00:00"
},
"location": "Oakland CA",
"title": "Test Post 1.4",
"album_id": 38,
"body": " This is the body",
"extract": "This is the extract",
"id": "b17caf88-c449-4e2a-8fee-f0e498f3d91c",
"photo": "http://fake-s3:4569/mra-images/uploads/photos/8abe3ad9-50d1-4c91-bbb7-6ca27fbad24c/medium.jpg"
}
}
],
"deleted": 1,
"errors": 0,
"inserted": 0,
"replaced": 0,
"skipped": 0,
"unchanged": 0
}
Rethink returns the proper json structure.
The text was updated successfully, but these errors were encountered:
Hi @cstetson. You should be using RunWrite instead of Run for write operations (see this). This will return a WriteResponse struct where you can simply access its Changes property. So it may look something like this:
I am working with a microservice application where I need to get back the values for a record that I delete and using the "ReturnChanges" feature of rethink is perfect for this. It works for update and replace, but fails for delete.
The return values for the changes come as
Where it should be returning the changes as an array:
Rethink returns the proper json structure.
The text was updated successfully, but these errors were encountered: