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
When and under what conditions Document.prototype.isNew returns true? #11990
Comments
From what i know, the document is considered // the following has "isNew = true"
const newDocNew = new SomeModel();
// after this function it has "isNew = false"
await newDocNew.save();
// the following has "isNew = true" only for some parts inside the function itself, the document returned should be "isNew = false"
const newDocCreate = await SomeMode.create();
// the following has "isNew = false"
const foundDoc = await SomeModel.findOne(); |
got it. Thank you! ✌️ |
We should improve the docs on this. The docs for |
@vkarpov15 What do you think about adding this information to the flag docs for the cases where it's used in 'post' hook? It's already in the docs but for 'Document.prototype.$locals'
tldr I forgot about that and spent 1 hour to debug why the flag is with value 'false' on insert in 'post' hook |
We'll add a note in the docs that |
docs(document): explain that `$isNew` is `false` in post('save') hooks
Prerequisites
Issue
First of all, thank you for your wonderful tool - mongoose!
What do you mean, "a new" document? Or, in other words, when and under what conditions a document is considered "new" and when it is not?
The documentation doesn't say anything about this.
The text was updated successfully, but these errors were encountered: