我有一个看起来像这样的模型
var UserSchema = new Schema({
id: ObjectId,
username: { type: String, trim: true, required: true, unique: true, lowercase: true },
location: [{ type: ObjectId, ref: 'Location', required: false }],
attachments: [{ type: ObjectId, ref: 'Attachment', required: false }]
})
当用户注册时,我需要在保存/创建用户以获取这些 ObjectId 之前创建位置和附件对象。我觉得我这样做的方式可能是错误的,这就是为什么它令人困惑或者我缺少一些东西。
我的问题是如何在保存用户集合之前保存这些集合,以便我可以将这些引用包含在我的用户集合中。
类似于这个问题,除了多个参考。