Skip to content
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

check that schema type is an object when setting isUnderneathDocArray #10361

Merged
merged 1 commit into from
Jun 15, 2021
Merged

check that schema type is an object when setting isUnderneathDocArray #10361

merged 1 commit into from
Jun 15, 2021

Conversation

vmo-khanus
Copy link
Contributor

@vmo-khanus vmo-khanus commented Jun 15, 2021

Summary
Originally mentioned here:
#10193 which was (at least partially for us) fixed by @vkarpov15

When checking if isUnderneathDocArray should be true for a given schema the root object of a sub document can be just 'nested' and so it throws an error: "Cannot create property '$isUnderneathDocArray' on string 'nested'".

This fix just slightly extends the work of @vkarpov15 by adding his fix to schemaType.schema.paths and schemaType.schema.subpaths in addition to schemaType.schema.singleNestedPaths.

More recently mentioned here:
#10357

Examples
Slightly modified version @IslandRhythms example (removed need to connect to db since this happens on schema compilation):

const mongoose = require('mongoose');
const Schema = mongoose.Schema;

const OutputSchema = new Schema({
      1: { left: { type: String }},
});

const AslSchema = new Schema({
  output: { type: OutputSchema }
});

const SessionSchema = new Schema({
  asls: { type: [AslSchema] }
});

const BlockSchema = new Schema({
  sessions: { type: [SessionSchema]  }
});

const Test = mongoose.model('Test', BlockSchema);

async function test() {
    await Test.validate({sessions: {asls: [{output: {1: {left: 'Test'}}}]}});
}

test();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants