-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Closed
Labels
confirmed-bugWe've confirmed this is a bug in Mongoose and will fix it.We've confirmed this is a bug in Mongoose and will fix it.
Milestone
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
8.3.1
Node.js version
v20.11.0
MongoDB server version
6.0.2
Typescript version (if applicable)
5.3.3
Description
/workspaces/example/node_modules/.pnpm/[email protected]/node_modules/mongoose/lib/cast.js:290
throw new StrictModeError(path, 'Path "' + path + '" is not in ' +
^
StrictModeError: Path "boo" is not in schema, strict mode is `true`, and upsert is `true`.
at cast (/workspaces/example/node_modules/.pnpm/[email protected]/node_modules/mongoose/lib/cast.js:290:17)
at model.Query.Query.cast (/workspaces/example/node_modules/.pnpm/[email protected]/node_modules/mongoose/lib/query.js:4786:12)
at model.Query.Query._castConditions (/workspaces/example/node_modules/.pnpm/[email protected]/node_modules/mongoose/lib/query.js:2199:10)
at model.Query._updateThunk (/workspaces/example/node_modules/.pnpm/[email protected]/node_modules/mongoose/lib/query.js:3752:8)
at model.Query._updateOne (/workspaces/example/node_modules/.pnpm/[email protected]/node_modules/mongoose/lib/query.js:3857:23)
at model.Query.exec (/workspaces/example/node_modules/.pnpm/[email protected]/node_modules/mongoose/lib/query.js:4330:80)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
at async main (/workspaces/example/main.ts:45:27) {
isImmutableError: false,
path: 'boo'
}
Steps to Reproduce
import mongoose from 'mongoose';
mongoose.set('translateAliases', true);
const main = async () => {
const uri = 'mongodb://root:example@mongodb';
const connection = mongoose.createConnection(uri, {
dbName: 'testdb',
});
connection.set('translateAliases', true);
console.debug('connection', connection);
const boo = 'boo';
const foo = 'foo';
const mongooseSchema = new mongoose.Schema({
B: {
alias: 'boo',
required: true,
unique: false,
type: String,
},
F: {
alias: 'foo',
required: true,
unique: true,
type: String,
},
});
const ExampleModel = connection.model('Example', mongooseSchema, 'example', {
overwriteModels: true,
});
const findResult = await ExampleModel.find({
boo,
});
console.debug('findResult', findResult);
const updateOneResult = await ExampleModel.updateOne(
{ boo },
{ foo },
{
upsert: true,
},
);
console.debug('updateOneResult', updateOneResult);
};
main();
Expected Behavior
No response
Metadata
Metadata
Assignees
Labels
confirmed-bugWe've confirmed this is a bug in Mongoose and will fix it.We've confirmed this is a bug in Mongoose and will fix it.