I use RethinkDB in my project and have the following table structure:
data_item {
id: "generated_thing",
slug: "slug"
}
aggregation_of_data_items {
items: ["some", "ids", "from", "data_item", "table"]
}
When I delete item from content table I want to keep data consistent - delete ID from aggregation_of_data_items.items array - is there any opportunity to do this in one request (something like $pull or $pullAll in MongoDB)?
To delete an item from an array you can do the following (this is in Python but it works in any supported language):
def remove(doc, value):
doc.replace(
lambda doc: doc.merge({"items" : doc["items"].set_difference([value])}))
Now we just need to run a query that does both, the easiest way to do this is to put them in an array:
[r.table("data_item").get(id).delete(),
remove(r.table("aggregation_of_..").get(...), id)]
.run()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With