Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 138249

Mongoose _id of type String not throwing error

$
0
0

I have a schema in Mongoose:

const member = new Schema({
  _id: { type: String, required: true },
  ...
});

but when I use await MemberModel.findOne({ _id: req.params.userID }); in an express request handler, I get a CastError: Cast to ObjectId failed for value "MY_SECRET_VALUE" at path "_id" for model "Member".

I have set the _id type in the Schema to a String so I don't understand why this is causing a problem. It should not be parsing the _id to an ObjectId - it should stay a String. I am trying to store a string in _id and then find all docs that match { _id: "MY_INPUT" }


Viewing all articles
Browse latest Browse all 138249

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>