I want to define Mongoose schemas with primary keys that are not _id. The documentation says it only allows the schema options flag _id to be set to false in subdocuments. Also, I want the primary key to be a String and not an ObjectId. Is that possible at all?
Using a secondary index is an option, but not a very good one since I want to have primary keys with proper names. I also don't want to fiddle around with two different indexes when I don't need to.
This sets documentId as a secondary index but that makes the primary key useless since I want to only select by documentId and not whatever _id ends up being set to automatically.
const DocumentSchema = new Schema({
documentId: { type: String, index: true }
})
I want to do something like
const DocumentSchema = new Schema({
documentId: String
})
and then tell it to use documentId as the primary key.
Clarification: I specifically don't want to use the _id as a key since it has an unhelpful name and I want to use documentId as the primary key instead.