I never used mongoose. but if _id
is not included in insert query, mongodb driver will generate _id
s for you as an ObjectId object. and if you wish to use your own _id
s, it's up to you to decide about its type and length, and also you have to guarantee its uniqueness among the collection because any attempt to insert a document with a duplicated _id
will fail.
accepted answer of this question may be useful, if you are looking for a method for creating custom _id
s that provides a decent degree of guaranteed uniqueness.