Describe deleteOne
or remove
method of Document in the doc
#14585
Labels
help
This issue can likely be resolved in GitHub issues. No bug fixes, features, or docs necessary
Prerequisites
Mongoose version
8.3.2
Node.js version
18.17.0
MongoDB server version
7.0.8
Typescript version (if applicable)
Not using.
Description
Please, note, I'm a new user of Mongoose and may get something wrong 🙂
I was reading the API reference and tripped over the
Document.prototype.$isDeleted()
example. It has this line:Previously I was using
Model.deleteOne()
to remove an entity, but the use ofDocument.prototype.remove
would be better it my case. So I went and gave it a shot, but it did not work.I checked sources and did not find any traces of
.remove
method for Document. So, I checked the types, and found.deleteOne
there.I tried
.deleteOne
, it worked. But I could not find this method in the doc. So, I'm not quite sure is it safe to use it? Search results do not show any results from e.g. FAQ.My best guesses are:
There are some methods that applied to the Document.prototype as “hooks”.
deleteOne
is one of them, same assave
. They are safe to use.Previously
deleteOne
was namedremove
, but was renamed. (According to Error: SubDocs.remove() is not a function #parent.children.id(_id).remove() --> "remove() is not a function" #13284 (comment)).The example with
product.remove
is outdated and should be rewritten with.deleteOne
.deleteOne
should be described in JSDoc like thesave
method. Without related code, just a JSDoc block for the API reference.If my guesses are correct, feel free to ping me, I will send a PR. If they are not, please, explain whether it's safe to use
deleteOne
, or not 🐨Steps to Reproduce
Model.findOne
..remove
on this document, getTypeError: doc.remove is not a function
..deleteOne
on this document, get no error..remove
, find it in an example..deleteOne
, find nothing.Expected Behavior
Document deletion method should be described in the doc properly. If it exists of course.
The text was updated successfully, but these errors were encountered: