-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
Failed to save document without define an _id in his model #7542
Comments
I might misunderstand your issue but be aware of this:
So you MUST create some unique field because otherwise there could exist 2 or more document with the exact same attributes/values. And if that's the case, you and mongoDB are unable to target one entry without the other. I hope this helps to clear things up for you. |
Hello mhombach, thank you for your reply. I'im just wondering, if lastest version changed something about that. |
The There is an exception: var subSchema = mongoose.Schema({
//your subschema content
},{ _id : false }); On first glance this might seem irritating, but you have to keep in mind the difference between mongoose and MongoDB. I don't think that this has changed in mongoose like.... ever.... EDIT: |
After reading your reply, i think i understood my problem.
Yes, that's it ! I tought that my field Otherwise, if i define In this situation, when _id: false is in wrong place, latest mongoose version is maybe more restrective than previous version. Again, thank you for your time and your help mhombach |
Glad we figured your probleme out :) |
I'm just saying, the latest version is maybe more restrective regarding model syntax since we conclude that i put I have not changed anything between mongoose version. With the model i showed you, this issue is gone when i come back to 5.4.10 and occure with the latest. Anyway, we found a solution to fix |
Hmm... ok, if you checked that the same code produces different behaviour with just the versions changing, then you maybe should create a new issue with that in focus. With a small script to reproduce the difference, maybe maintainers can check if this is wanted behaviour or not :) |
@mhombach You're right about _id in the wrong place. However, this issue has nothing to do with the user failing to create an _id, they should not have to in this case because they aren't disabling _id on the top level schema @Royalsspirit there will be a fix for this issue in 5.4.16, this issue was also reported in #7524. Please see my comments here: #7524 (comment) |
@vkarpov15 Thank you very much for your reply. |
Do you want to request a feature or report a bug?
Report a bug introduice since 5.4.11
What is the current behavior?
Since 5.4.11, an error occure when i want to save this document:
It's like mongoose don't generate an
_id
by default like in previous version.I tried many things to fix the issue and i found that when i remove
_id:false
fromuser
. I get what i expected or an other way is to define a_id
in main document likeIf the current behavior is a bug, please provide the steps to reproduce.
What is the expected behavior?
Expect document has been created but have
document must have an _id before saving
mongooseError without any unique ID in my model but it worked before 5.4.10Please mention your node.js, mongoose and MongoDB version.
node: v9.0.0
mongodb: v4.0.0
mongoose: v5.4.14
The text was updated successfully, but these errors were encountered: