About removing items

Hi!

I have a collection with ~3000 items.

And I have this method:

'client.remove.all': function (structureId) {
    console.log("client.remove.all [start]")
    Clients.remove({structureId});
    console.log("client.remove.all [end]")
  },

In that moment, the user has a subscription to this “clients” collection.

When I execute it:

  • it removes the items in the collection (ok)
  • But the collection count in the browser stops in a random number, arround the middle of the con (i.e.: the collection has 3000 items, it stucks in ~1400 - ~1600 items.
  • The CPU goes to 100%
  • Meteor takes too long to new subscriptors.
  • Never prints the “client.remove.all [end]” (ok, never in 20 minutes running)

This doesn’t happen if I remove the collection in mongodb (I did it with robomongo and the shell).

Someone knows where can be de problem?

Thanks!!!

Someone know

First, subscribing to 3k items seems like overkill – why are you subbing to so many at once?

Second, if you aren’t wrapping your method with an if (Meteor.isServer) block, then you will be getting optimistic ui updates, which is probably not going to be very performant when you are subbed to 3k documents.

I’d probably look first to reduce your subscription to something more manageable. If for some reason you need to subscribe to that many docs, I’d probably unsubscribe when you call your method, show a spinner or something, then resubscribe on a method callback.

1 Like