I want to delete some records after sort and skip items but this query always delete all records after find.as if sort and skip don’t do anything’:
await Book.find(Book.owner.id == user.id).sort("-created_at").skip(2).delete()
I want to delete some records after sort and skip items but this query always delete all records after find.as if sort and skip don’t do anything’:
await Book.find(Book.owner.id == user.id).sort("-created_at").skip(2).delete()
2
Answers
We can delete the items by beanie functionality like this:
To achieve the target you can first fetch the docs by applying a skip function & then use deleteMany function.
Note: You can also use sort({_id:-1}) to sort the docs.
See the Example code below-