Closed hannomalie closed 5 years ago
I just tried and cannot reproduce the error.
create the collection with empty hooks array
$ curl -v -u a:a -X PUT http://localhost:8080/db/mycollection --header "content-type: application/json" --data '{"hooks": []}'
< HTTP/1.1 201 Created
add the hook
$ curl -v -u a:a -X PATCH http://localhost:8080/db/mycollection --header "content-type: application/json" --data '{"hooks": [{"name":"metricsHook"}]}'
< HTTP/1.1 200 OK
check that hook is actually defined (getting warning since hook is not defined in the configuration)
$ curl -v -u a:a http://localhost:8080/db/mycollection
< HTTP/1.1 200 OK
{
"_embedded": [],
"_id": "mycollection",
"hooks": [{
"name": "metricsHook"
}],
"_etag": {
"$oid": "5beac97233efcc15d2cbd4c1"
},
"_returned": 0,
"_warnings": ["error applying hook: no singleton configured with name: metricsHook"]
}
remove the hook from collection properties
$ curl -v -u a:a -X PATCH http://localhost:8080/db/mycollection --header "content-type: application/json" --data '{"hooks": []}'
< HTTP/1.1 200 OK
{
"_warnings": ["error applying hook: no singleton configured with name: metricsHook"]
}
test that everything is fine
$ curl -v -u a:a http://localhost:8080/db/mycollection
< HTTP/1.1 200 OK
{
"_embedded": [],
"_id": "mycollection",
"hooks": [],
"_etag": {
"$oid": "5beac9e033efcc15d2cbd4c3"
},
"_returned": 0
}
regarding the partial updates, this is exactly the semantic of the verb PATCH.
from https://restheart.org/learn/write-requests/
While PUT and POST verbs replace the whole state of the resource identified by the request URL, PATCH verb only modifies the properties passed with the request JSON body.
Also you can use the mongodb update operators
this removes the hooks property
$ curl -v -u a:a -X PATCH http://localhost:8080/db/mycollection --header "content-type: application/json" --data '{"$unset": {"hooks":true}}'
this removes the first element of the array hooks
$ curl -v -u a:a -X PATCH http://localhost:8080/db/mycollection --header "content-type: application/json" --data '{"$pop": {"hooks":-1}}'
Thank you a ton for your fast answer - we're going to check this again with our setup as soon as we can and give you feedback :)
closing for now. feel free to reopen with more information
I can confirm that this works. No idea what we did back then that made us believe it doesn't work though.. Thank you for your efforts, great job, as always :)
We want to eliminate obsolete hooks from collections without deleting the collections.
Expected Behavior
We used hooks to gather request metrics in our restheart-based stack. Since we added metrics to restheart as a pull request some time ago, our hooks are obsolete now. There is a way to remove all hooks metadata from collections without the need for deleting collections.
Current Behavior
We wanted to remove the hooks from existing data, but didn't find a way to do it. The documentation doesn't give any hints on that. Patching hooks with an empty array gives an error.
Environment
Restheart version 3.4.2 MongoDB version 3.4.10
Steps to Reproduce
Possible Implementation
Thanks guys :)