Можно ли ссылаться на ту же схему при создании новой схемы Mon goose? - PullRequest
0 голосов
/ 18 апреля 2020

Можно ли ссылаться на ту же схему при создании новой схемы Mon goose? Я создаю схему Person, и в некоторых ее ключах я пытаюсь использовать ту же схему в качестве ссылки. Но как я могу это сделать, поскольку я хочу сослаться на схему, которая еще не существует? Вот как выглядит моя схема:

    const personSchema = new mongoose.Schema({
      additionalName: String,
      address: {
        type: mongoose.SchemaTypes.ObjectId,
        ref: PostalAddress,
      },          
      award: String,
      birthDate: Date,
      birthPlace: {
        type: mongoose.SchemaTypes.ObjectId,
        ref: Place,
      },
      callSign: String,
      children: {
        type: mongoose.SchemaTypes.ObjectId,
        ref: "Person",
      },
      colleague: {
        type: mongoose.SchemaTypes.ObjectId,
        ref: "Person",
      },
      deathDate: Date,          
      email: String,
      familyName: String,
      follows: {
        type: mongoose.SchemaTypes.ObjectId,
        ref: "Person",
      },
      funder: {
        type: mongoose.SchemaTypes.ObjectId,
        ref: Organization,
      },
      gender: {
        type: mongoose.SchemaTypes.ObjectId,
        ref: Gender,
      },
      givenName: String,
      jobTitle: String,
      knowsLanguage: {
        type: mongoose.SchemaTypes.ObjectId,
        ref: Language,
      },
      memberOf: {
        type: mongoose.SchemaTypes.ObjectId,
        ref: Organization,
      },
      nationality: {
        type: mongoose.SchemaTypes.ObjectId,
        ref: Country,
      },
      relatedTo: {
        type: mongoose.SchemaTypes.ObjectId,
        ref: "Person",
      },
      sibling: {
        type: mongoose.SchemaTypes.ObjectId,
        ref: "Person",
      },
      spouse: {
        type: mongoose.SchemaTypes.ObjectId,
        ref: "Person",
      },
      telephone: String,
      worksFor: {
        type: mongoose.SchemaTypes.ObjectId,
        ref: Organization,
      },
      image: String,
    });

    exports.default = mongoose.model('person', personSchema);
...