-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Closed
Labels
Stalecan't reproduceMongoose devs have been unable to reproduce this issue. Close after 14 days of inactivity.Mongoose devs have been unable to reproduce this issue. Close after 14 days of inactivity.
Description
Prerequisites
- I have written a descriptive issue title
- I have searched existing issues to ensure the bug has not already been reported
Mongoose version
6.4.5
Node.js version
16.15.0
MongoDB server version
4.0.4
Description
The inserted document will have an "ObjectId" _id despite using _id: String
in a schema.
new mongoose.Schema({ _id: String }, { strict: false })
Steps to Reproduce
- Create a new model with
_id: String
in the schema
const schema = new Schema({ _id: String }, { strict: false});
const MyModel = mongoose.model('MyModel', schema);
- Use
findOneAndUpdate
with upsert option to create a new document:
// since the doc doesn't exist, it will be inserted thanks to the upsert option
const res =
await MyModel.findOneAndUpdate(
{ foo: "bar" },
{},
{ upsert: true, returnDocument: "after" }
);
The document will have an ObjectId
_id, the String
type is not respected.
Expected Behavior
The new document should have a string _id.
Metadata
Metadata
Assignees
Labels
Stalecan't reproduceMongoose devs have been unable to reproduce this issue. Close after 14 days of inactivity.Mongoose devs have been unable to reproduce this issue. Close after 14 days of inactivity.