Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

No _id field when adding object to array in collection

I have a collection in Mongodb I’m accessing in my app and connecting through ReactJS and mongoose. On this collection I have a property that is set to an Array type. When I add to that Array, it does so successfully, however I DO NOT see an _id field that should be automatically be created. Why would this be happening? Thanks.

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Id fields are only added to top-level-documents, not to sub-documents in arrays. If you want to have ids on the sub-documents, you need to add them to your schema manually when saving.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading