stupid question: what type should we assign for the autogenerated ObjectId?
See original GitHub issueI’ve been defining some of them as:
@prop({ auto: true })
_id?: mongoose.Schema.Types.ObjectId;
But it eventually started to cause issues when making references to it and treating it as string in my app.
Does it make any difference if I just define it as as tring as opposed to the ObjectId type?
Thanks!
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:16 (6 by maintainers)
Top Results From Across the Web
In MongoDB, should I store the user id in the _id field or in id ...
Yes, what you think is right. You should use the automatically generated _id from MongoDB to identify the user uniquely, there is no...
Read more >Migrate Primary Keys to UUIDs - Sequelize/Node
Step 4: Change all of the Sequelize models to use UUIDs This step meant to go into each model and update each primary...
Read more >Collection need to have ids from 2 other different ... - MongoDB
I am creating my first project using MongoDB. Where there is a need of having two foreign keys in a collection if I...
Read more >cannot read properties of undefined react
There a re two solutions for this problem. But I have problem with GlobalStore (Context API). Bug]: Cannot read property '_f' of undefined...
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 Free
Top 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
you said something about “dynamic package” could you explain a bit more? maybe if you cant import everything, try
import { Types } from "mongoose"; Types.ObjectId
also i had: TypeError: Cannot read property ‘ObjectId’ of undefined for this:
mongoose.Types.ObjectId
Changed this to this: