-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Updating a subdocument with Model.updateOne complains with "missing following properties of LeanDocument: ownerDocument, parent " #10597
Comments
Try upgrading to v5.13.9, it looks like this may have been fixed with #10647 . I can confirm the below script fails to compile with v5.13.7 but compiles successfully with v5.13.9. import { Document, connect, model, Schema } from 'mongoose';
run().catch(err => console.log(err));
async function run() {
await connect('mongodb://localhost:27017/test');
interface IGameEventDocument extends Document {
description: string;
}
interface IGameDocument extends Document {
name: string;
events: IGameEventDocument[]
}
const schema = new Schema<IGameDocument>({ name: String, events: [{ description: String }] });
const GameModel = model<IGameDocument>('Game', schema);
const doc = await GameModel.findOne().orFail();
await doc.update({ events: [{ description: 'test' }] });
} |
@vkarpov15 In my case, export type IGameEventDocument = IGameEvent & Types.Subdocument;
const gameRecord = await Game.findByIdAndUpdate(upcomingGame._id, {
status: GameStatus[fixture.status.short],
awayTeamScore: goals.away,
homeTeamScore: goals.home,
venue: fixture.venue.name,
date: new Date(fixture.date),
// Type 'IGameEvent[]' is not assignable to type 'IGameEventDocument[]'.
// Type 'IGameEvent' is not assignable to type 'IGameEventDocument'.
// Type 'IGameEvent' is missing the following properties from type 'Subdocument': $isSingleNested, ownerDocument, parent, $parent, and 51 more.
events: FootballApiMappings.mapFixtureEvents(events), // <- Error here
}); |
@Duchynko Fix will be in v6.0.8. Are you able to upgrade to v6 or is there something that's blocking you from upgrading? |
Thanks a lot @vkarpov15. I'll update to 6.0.8 👍🏼 |
Discussed in #10595
Originally posted by Duchynko August 24, 2021
Mongoose version: 5.13.7
After an update from 5.11.17 to 5.13.7, I'm seeing this error when trying to update a list of subdocuments.
How can I update a subdocument with a plain object?
Thanks :)
The text was updated successfully, but these errors were encountered: