bi-tm / express-nedb-rest

rest api for nedb database, based on express http server
MIT License
24 stars 13 forks source link

How to delete by field other than id #4

Closed ghost closed 8 years ago

ghost commented 8 years ago

I'm wanting to use this module in a project but the items I'd want to delete I would not know the id of. A customer would insert the field and if present it should be deleted . I'm relatively new to rest and xmlhttprequest so not sure if there is a way to do this with your module. The field the customer would be entering would be unique so no concerns about too many or the wrong entry being deleted.

bi-tm commented 8 years ago

Hello, i like to suggest three solutions: 1) perhaps you are able to store the given unique value as _id. then you can access and also delete the dataset easily. 2) You can search the document by GET with the $filter parameter. if the query returns the dataset, you will also get it's _id, and can delete it with a DELETE. 3) You can also call DELETE directly with $filter parameter. All datasets, which match the filter, will be deleted. Keep in mind, that you will delete multiple documnets, if the filter mathes. Good luck, Torsten

ghost commented 8 years ago

Thank you, I actually hadn't thought of the first option, I may switch to that method as it would make it easier to find and delete data when needed, and would also allow easy expansion if needed. I was Abe to get it working deleting with the filter. Thank you for your help and a great module. The simplicity of it made it easy to get setup quickly.