How to define an objectId type in mongoose 6.0.0^

I am seeing many answers saying that the correct way to define an objectId type in a mongoose schema is like:

type: mongoose.Schema.Types.ObjectId

But from the mongoose docs they show that you can define an objectId type like so:

const carSchema = new mongoose.Schema({ driver: mongoose.ObjectId });

Is there something I am missing? What is the correct way to define an objectId type? Are both methods correct or one is outdated?

1 answer

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum