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

[BUG] [5.12.7] Cannot create property '$isUnderneathDocArray' on string 'nested' #10193

Closed
gilles-yvetot opened this issue Apr 29, 2021 · 9 comments
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it.
Milestone

Comments

@gilles-yvetot
Copy link

Do you want to request a feature or report a bug?
bug

What is the current behavior?
Cannot create property '$isUnderneathDocArray' on string 'nested'

If the current behavior is a bug, please provide the steps to reproduce.

run this script:

const { Schema } = require('mongoose')

const DynamicTextMatchFeaturesSchema = new Schema({
  css: { color: String },
})

const PossibleElementsArraySchema = {
  type: [
    {
      textMatchFeatures: {
        dynamic: { type: DynamicTextMatchFeaturesSchema },
      },
    },
  ],
}

const ElementSchema = new Schema({ image: { type: String } })

const possibleElementsStrategy = {
  possibleElements: PossibleElementsArraySchema,
}

ElementSchema.add(possibleElementsStrategy)

What is the expected behavior?

To not print this message

What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
Node 14.15.1
Mongoose 5.12.7 it is working fine with 5.12.5 but not 5.12.7

@erikonrombosman
Copy link

erikonrombosman commented Apr 29, 2021

const UserSchema = new Schema({
  name: {type: String, required: true, trim: true},
  gender: {type: String, enum: ['male', 'female', 'none']},
  email: {
    type: String,
    lowercase: true,
    required: true,
    trim: true,
    validate: [
      {validator: (value) => validator.isEmail(value), msg: 'Invalid email.'},
    ],
  },
  customerId: {type: String},
  externalId: {type: String},
  domain: {type: [String], trim: true, default: []},
  blockedDomains: {type: [String], trim: true, default: []},
  roles: [{type: String, enum: [
    'superadmin',
    'admin',
    'seller',
    'picker',
    'picker-admin',
    'user',
    'callcenter',
    'analyst',
    'analyst-1',
    'analyst-2',
    'analyst-3',
    'mobile-app-usage-report',
    'admin-app-usage-report',
  ]}],
  permissions: [{type: String}],
  profilePicture: String,
  password: {type: String, select: false},
  salt: {type: String, select: false},
  address: [AddressSchema],
  socialLogins: {
    fbId: {type: String, unique: true, sparse: true},
    googleId: {type: String, unique: true, sparse: true},
  },
  phone: {type: String},
  blocked: {type: Boolean, default: false},
  verified: {type: Boolean, default: false},
  active: {type: Boolean, default: true},
  sellerToken: {type: String, unique: true, required: true, default: randomstring.generate},
  recoverToken: {
    value: {type: String, select: false},
    expiresAt: {type: Date, select: false},
  },
  authorizedByVerification: {type: Boolean, default: false},
  verifyToken: {
    value: {type: String, select: false},
  },
  rut: {type: String},
}, {
  timestamps: true,
  usePushEach: true,
});

Having the same issue

/usr/app/node_modules/mongoose/lib/schema.js:782
schemaType.schema.singleNestedPaths[key].$isUnderneathDocArray = true;
TypeError: Cannot create property '$isUnderneathDocArray' on string 'nested'

using "mongoose": "^5.11.18", running on ubuntu 20.04, on minikube

@gilles-yvetot
Copy link
Author

@erikonrombosman what's the exact version version installed on your machine? Not the one from package.json ?

@erikonrombosman
Copy link

@erikonrombosman what's the exact version version installed on your machine? Not the one from package.json ?

i was using "mongoose": "^5.11.18" in package.json, but changing to 5.12.5 and making some change on DockerFile fixed the problem (I know is weird)

@gilles-yvetot
Copy link
Author

@erikonrombosman if you use the exact mongoose version to 5.12.5 or before it should work. If you use something with the caret ^ it will install the latest one 5.12.7 causing issue

@vmo-khanus
Copy link
Contributor

@erikonrombosman what's the exact version version installed on your machine? Not the one from package.json ?

i was using "mongoose": "^5.11.18" in package.json, but changing to 5.12.5 and making some change on DockerFile fixed the problem (I know is weird)

@erikonrombosman - can you elaborate on the "some change on DockerFile"?

We're using mongoose 5.9.24 on Node 12/14 in AWS Lambda and this started showing up out of nowhere (exact same error).

@louisnow
Copy link

louisnow commented May 3, 2021

Same problem on Node 12/14.
Using 5.12.5 worked

@Jule-
Copy link

Jule- commented May 3, 2021

I can confirm too.

@IslandRhythms IslandRhythms added the confirmed-bug We've confirmed this is a bug in Mongoose and will fix it. label May 4, 2021
@IslandRhythms
Copy link
Collaborator


const mongoose = require('mongoose');
const { Schema } = require('mongoose');

const DynamicTextMatchFeaturesSchema = new Schema({
  css: { color: String },
})

const PossibleElementsArraySchema = {
  type: [
    {
      textMatchFeatures: {
        dynamic: { type: DynamicTextMatchFeaturesSchema },
      },
    },
  ],
}

const ElementSchema = new Schema({ image: { type: String } })

const possibleElementsStrategy = {
  possibleElements: PossibleElementsArraySchema,
}

ElementSchema.add(possibleElementsStrategy);

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

async function test() {
    await mongoose.connect('mongodb://localhost:27017/test', {
        useNewUrlParser: true,
        useUnifiedTopology: true
      });
     await  Test.create({image: 'image' });
}
test();

@gilles-yvetot
Copy link
Author

@IslandRhythms you don't even need to actually connect to a database for the bug to occur

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it.
Projects
None yet
Development

No branches or pull requests

7 participants