If you explicitly declare _id: Schema.ObjectId for your model, then the ObjectId will not be available after new or save.
See original GitHub issueIf you explicitly declare
_id: Schema.ObjectId
for your model, then the ObjectId will not be available after new or save.
Issue Analytics
- State:
- Created 11 years ago
- Comments:6
Top Results From Across the Web
is there a way to auto generate ObjectId when a mongoose ...
If you create a new document without an _id field, MongoDB automatically creates the field and assigns a unique BSON ObjectId. Share.
Read more >Mongoose v6.8.2: Schemas
Mongoose assigns each of your schemas an _id field by default if one is not passed into the Schema constructor. The type assigned...
Read more >Express Tutorial Part 3: Using a Database (with Mongoose)
It explains how object schema and models are declared, the main field types, and basic validation. It also briefly shows a few of...
Read more >Mongoose | Ts.ED - A Node.js and TypeScript Framework on ...
This tutorial shows you how you can use mongoose package with Ts.ED. ... import {Property} from "@tsed/schema"; import {Model, ObjectID} ...
Read more >MongoDB Schema using Mongoose - Arun Rajeevan - Medium
Note: When there's no document, parent.author will be null. If you have an array of authors in your parent Schema , populate() will...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
ah, the docs were incorrectly hiding the option you need (will be fixed next time they’re published).
you must pass the
auto
option like so:new Schema({ _id: { type: Schema.ObjectId, auto: true }}) “CHANGE (_id) to (id)”