Following this tutorial, I have a mongoose model: (I\'m using the term \"Account\" instead of \"Todo\", but it\'s the same thing)
const Account = mongoose.m
So what I just found is that _id
is of type ObjectID
but seems to implicitly cast to String
. So if you define your mongoose model id type to be String
instead of mongoose.Schema.Types.ObjectId
then it should work. Using your current code (from the compose.com tutorial) that copies _id to id, the result will be that, in Mongo (after saving), the _id will be of type ObjectID
and your model id will be of type string.
In other words, instead of this
const Account = mongoose.model('Account', new mongoose.Schema({
id: mongoose.Schema.Types.ObjectId,
name: String
}));
Do this
const Account = mongoose.model('Account', new mongoose.Schema({
id: String,
name: String
}));