Skip to content

Incorrect behavior in a shard cluster #361

@sarkistlt

Description

@sarkistlt

Currently .remove method always uses findAndModify. It should use deleteOne if ctx.id is present.

Main problem right now it's not possible to remove document by _id without passing shard key, because .remove uses findAndModify, if it would use deleteOne you'll be able to remove document just by _id, without passing extra query with sharding key.

This is my current workaround, in before remove hook:

if (
    ctx.id
    && ctx.service
    && ctx.service.Model
  ) {
    await ctx.service.Model.deleteOne({ ...(ctx.params.query || {}), _id: ctx.id });
    ctx.result = { _id: ctx.id };
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions