我阅读了官方文档,但仍然不明白https://docs.mongodb.com/manual/tutorial/model-embedded-one-to-one-relationships- Between-documents/ Between-documents/ \n请解释一下,如何在我的示例中创建。\n我有带有猫鼬的 Nest.js 应用程序。\n两个架构(数据库中的 2 个表):
\n1)
\nexport type UserModelDocument = UserModel & Document;\n\n@Schema()\nexport class UserModel {\n @Prop()\n email: string;\n\n @Prop({ type: MongooseSchema.Types.ObjectId, ref: \'InviteModel\' })\n invite: InviteModel;\n}\n\nexport const UserSchema = SchemaFactory.createForClass(UserModel);\nRun Code Online (Sandbox Code Playgroud)\n@Schema()\nexport class InviteModel {\n\n @Prop()\n status: string;\n}\n\nexport const InviteSchema = SchemaFactory.createForClass(InviteModel);\nRun Code Online (Sandbox Code Playgroud)\n在这里,在我的服务中我创建了一个用户:
\nasync create(createUserDto: CreateUserDto) {\n const userExists = await this.userModel.findOne({ email: createUserDto.email });\n if (userExists) {\n this.logger.error(\'User already exists\');\n throw new NotAcceptableException(\'User already exists\');\n }\n const …Run Code Online (Sandbox Code Playgroud)