简体   繁体   中英

How to send custom property name in delete option using feathersjs

I want to delete the document in a collection., In feathers accept only id not any specific property name for deletion.

My url is: http://localhost:8080/workers?userId=3

function(hook,next){
      if(hook.params.query.userId){
          hook.app.service('users')
            .remove({ query: {userId: hook.params.query.userId}})
            .then(result=>{
              console.log(result,'result');
              });
      } else {
        next();
      }
    }

You can pass null as the id to remove to remove entries according to a query. It is documented here and here . So

hook.app.service('users').remove(null, { query: {userId: hook.params.query.userId}})

Should do what you want.

You will need to find the id of the document and then pass that into the remove method afaik. This is much safer than attempting to delete on a property value.

Send the extra parameters as query parameters in the URL eg

/delete/<id>/?param1=value1&param2=value2

then access these parameters in your service as

const {param1, param2} = params.query;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM