-
-
Notifications
You must be signed in to change notification settings - Fork 750
-
-
Notifications
You must be signed in to change notification settings - Fork 750
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
update, remove and patch many #144
Comments
Personally I'm currently in favour of option #2 and shipping it with Feathers 2.0. |
Definitely option 2, and we do need createMany support. |
Doesn't |
Oh, Yes. To be clear, I meant createMany behavior, not that specific name in the API. |
I agree. This should definitely be in core. I had done custom services and hooks to make this happen in previous projects. |
What would a batch update look like? PUT an array of objects with their ids intact? Same for PATCH? And for DELETE, an array of ids [ 1, 2, 3 ] and/or an array of objects with ids? |
What’s needed to make this happen?
|
I was thinking of things like like Batch update and patch behaviour is more interesting. Probably if you do something like |
That sounds good to me. I can't think of a case where batch update would be useful. Patch, sure. |
Good point. I didn't even think about sending an event for each item in the array but that's the way to go. So the core changes I think would be neccessary:
I am currently working on making https://github.com/feathersjs/feathers-memory a reference adapter with the supported functionality and documentation so that we can update the other ones accordingly. I think - although core supports it - the officially supported adapters shouldn't support batch |
Thanks for that, but there is still no possibility to send an array in body in the delete-Request, to remove more than one document. So "/ DELETE / -> service.remove(null, data, params)" not really works, you just get the same response like with id. Only with null for id. I guess, you have to change // Returns the leading parameters for a `get` or `remove` request (the id)
function reqId (req) {
return [ req.params.id || null ];
} to // Returns the leading parameters for a `get` or `remove` request (the id)
function reqId (req) {
return [ req.params.id || null, req.body ];
} in your wappers.js And in your feathers-commons/arguments.js some changes in the " getOrRemove(name)"-function are necessary to fix it. What do you think? |
I know that the spec doesn't explicitly state that you can or can't send a body for DELETE requests but what does the data you want to send look like in your case? Our thinking for delete-many was being able to do things like |
I understand your thinking and in many cases it's completely sufficient, but if you want delete many documents by id, which can't be found by a query, it doesn't work. In this case you need the possibility to send an array with this id's in body. For example, if the user select the documents to delete in a list. Of course, you could fire for every document a delete-Request or write your own delete-route-Function directly with the express router, but it would be more efficient to handle it all in feathers with just one DELETE-Request. |
You should be able to use |
@marshallswain for an mongoDB/ Mongoose query I would use it for sure, but this doesn't solve the described problem. To use the id's in this case, you have to get them first. I prefer to get the id's in array in the body of a DELETE-Request, but this is currently not possible in feathers. Alternative you could use an own POST-Request with the data in body for deleting more then one document, but it would be better and easier to handle it in a DELETE-Request. |
All of the feathers adapters will allow you to use that syntax, not just
How would you get the ids in the body of the delete request? What would Is the problem the response? Maybe DELETE should return an array of deleted
|
like a POST-Request. In short: A payload (Body) with the id's in it in a DELETE-Request would be perfect. That's what I understood in your code with
(https://github.com/feathersjs/feathers/blob/master/lib/providers/rest/index.js#L59) where 'data' would be the payload. Otherwise, it should be
The response wouldn't be a problem. Thanks for your help. |
You're right, that's definitely a copy & paste mistake in the comment. Thanks for pointing that out, I just fixed it. I'm still not sure if we're only talking about the difference of making a request like
And sending
in the body? If you would rather send it in the body you could map it to the parameters in a middleware like this: app.use('/todos', function(req, res, next) {
if(req.method === 'DELETE') {
req.feathers.body = req.body;
}
next();
}, {
remove: function(id, params, callback) {
if(id === null) {
doSomething(params.body);
}
}
}); |
A little nicer would be to map the query to the body in a similar middleware like this: app.use('/todos', function(req, res, next) {
if(req.method === 'DELETE') {
req.feathers.query = Object.assign(req.feathers.query || {}, req.body);
}
next();
}, {
remove: function(id, params, callback) {
if(id === null) {
doSomething(params.query);
}
}
}); Which allows to send any DELETE query also as the body. |
Ya I was/am a bit confused as well. Sorry I'm a bit slow... If I understand correctly @daffl's solution should work fine for your use case. I'm not entirely sure why you wouldn't want to just send the ids in the query string like so:
Are there a lot of ids and the query string is too long? Readability an issue? Not trying to be a dick, just genuinely trying to understand the problem. |
And I'm realizing that I was completely ignorant that DELETE requests weren't already in the body. I just assumed they were. |
@daffl your last update, that might be a pretty negligible change in core that would support this. I just want to get a better handle on the use case first. I've never had to send data in the body as part of a delete request. |
@daffl Thanks a lot, that's it. This solution works perfect for me. ;) Interesting Article about Url-Length: |
@MichaelPlan sounds good. Glad that solved your problem. Thanks for sharing that link. We are aware of the query string limitations but so far have never really run into that problem. (Although we had talked about it in the past) @daffl Since it isn't explicit in the spec, what are your thoughts on moving that into core? Quickly looking at our core code, I'm inclined to just document how to patch it like above (just not sure where these one off examples should go). Maybe FAQ for now? |
I'm glad that worked! I think we can just put it in the FAQ for now. Also, if anybody is running into other querystring limitations, feathers-batch might be useful because it lets you POST all your methods parameters. |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue with a link to this issue for related bugs. |
Sometimes you want to update multiple resources e.g. via REST sending a
PUT /todos
orDELETE /todos
. Supporting this is fairly easy, the question is what method signatures to use. Currently I see two options.Option 1:
*Many
service methodsWe could add
updateMany
,patchMany
andremoveMany
(and possiblycreateMany
although it would just be passing an array tocreate
).Option 2:
null
values forid
The other option is to pass a
null
value as an id when operating on multiple resources.notFound
error)The text was updated successfully, but these errors were encountered: