Skip to content
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

How to make .remove(null) not to return all removed documents #439

Open
fmoessle opened this issue Nov 20, 2022 · 2 comments
Open

How to make .remove(null) not to return all removed documents #439

fmoessle opened this issue Nov 20, 2022 · 2 comments

Comments

@fmoessle
Copy link

MongoDB: 4.2.17
feathers-mongoose: 8.5.1
@feathers/feathers: 4.5.15

Hi!

Currently calling .remove(null) on a service returns all removed documents.

// assuming we have a service called "books"
await feathers.service('books').create({ title: 'The Lord of the Rings' })

// this will return [{ title: 'The Lord of the Rings' }]
await feathers.service('books').remove(null)

// this will also return [{ title: 'The Lord of the Rings' }]
await feathers.service('books').remove(null, {
  query: {
    $limit: 0
  }
)

While this is fine for a small number of removed documents, when the number get's higher (in our case 50k+)
things start to get very slow.

Is there a way to avoid this?

@DaddyWarbucks
Copy link

This should also be implemented for create and patch.
See also: feathersjs-ecosystem/feathers-mongodb#219

@DaddyWarbucks
Copy link

@fmoessle The best way to avoid this until the library is updated is to use an after hook to unset the results. For example

// I wouldn't use $limit: 0 just yet. That may cause patch/remove to not
// actually update any records? I know your example says it works and that is
// good, but I am not sure thats the case for patch too? So I wrote this to use
// $returning similar to feathers-sequelize until we can ensure $limit: 0 is
// correct.
const handleMulti = (context) => {
  const { id, params } = context;

  if (id) {
    return context;
  }
  // if (params && params.query && params.query.$limit === 0) {
  //   context.result = [];
  // }

  if (params && params.query && params.query.$returning === false) {
    context.result = [];
  }
  
  return context;
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants