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

Mongoose 5.7.5 Cannot read property 'split' of undefined #8251

Closed
d4rth-v4d3r opened this issue Oct 15, 2019 · 10 comments
Closed

Mongoose 5.7.5 Cannot read property 'split' of undefined #8251

d4rth-v4d3r opened this issue Oct 15, 2019 · 10 comments
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it.
Milestone

Comments

@d4rth-v4d3r
Copy link

d4rth-v4d3r commented Oct 15, 2019

BUG

{ "name": "TypeError", "message": "Cannot read property 'split' of undefined", "stack": "TypeError: Cannot read property 'split' of undefined\n at SingleNested.Subdocument.isModified (/home/node/app/ne-route-droker-api/node_modules/mongoose/lib/types/subdocument.js:120:51)\n at SingleNested.<anonymous> (/home/node/app/ne-route-droker-api/node_modules/mongoose/lib/schema.js:1113:60)\n at callMiddlewareFunction (/home/node/app/ne-route-droker-api/node_modules/kareem/index.js:482:23)\n at SingleNested.next (/home/node/app/ne-route-droker-api/node_modules/kareem/index.js:58:7)\n at _next (/home/node/app/ne-route-droker-api/node_modules/kareem/index.js:106:10)\n at process.nextTick (/home/node/app/ne-route-droker-api/node_modules/kareem/index.js:507:38)\n at process._tickCallback (internal/process/next_tick.js:61:11)" }

My code was working like a charm and I update from 5.7.1 to 5.7.5 and suddenly this error start happening. I did not write any change in my code. I revert to version 5.7.1 and everything works again.

I built a Docker Image over Ubuntu 16.04.

Mongo 4.1
Node 10 LTS
Mongoose version 5.7.5

@Youssefares
Copy link

This is happening in my system as well. Has to do with #8223
It occurs when saving any record for me (at least records with a subdocument).

@BastienScanu
Copy link

I got the same problem, upgrading from v5.6.11 to 5.7.5. Every time I try to save a document in one of my collections I get this error, but other collections work just fine. The problematic collection has subdocuments. I fixed my problem by going back to v5.6.11.

@saveman71
Copy link
Contributor

saveman71 commented Oct 17, 2019

Same here, here is a repro:

'use strict';

const Promise = require('bluebird');
const mongoose = require('mongoose');
mongoose.Promise = Promise;

// DB
let connect = mongoose.connect('mongodb://localhost:27018/test', {
  useNewUrlParser: true,
  useUnifiedTopology: true,
});

const ActivitySchema = new mongoose.Schema({
  description: {
    type: String,
    required: true,
  },
}, {
  timestamps: true,
  _id: false,
});

const RequestSchema = new mongoose.Schema({
  name: {},
  activity: ActivitySchema,
});

const Request = mongoose.model('Request', RequestSchema);

// Create test data
connect.then(async () => {
  mongoose.connection.db.dropDatabase();

  const request = await Request.create({
    name: 'lol',
    activity: {
      description: 'title',
    },
  });

  request.activity.set({
    description: 'foo',
  })

  // Will fail
  await request.save();

  // Log request
  console.log(request);
});

I initially thought it was due to the timestamp option but it appears this is more general It seems to work if I disable the timestamps option. Please tell me if that's another bug!

Works fine in 5.7.4, makes sense since the code was introduced in 327b47a

@vkarpov15 vkarpov15 added this to the 5.7.6 milestone Oct 17, 2019
@vkarpov15 vkarpov15 added the needs repro script Maybe a bug, but no repro script. The issue reporter should create a script that demos the issue label Oct 17, 2019
@stieg
Copy link
Contributor

stieg commented Oct 18, 2019

Error for me stems from lib/schema.js:1113 where this.isModified() is called without arguments. However it seems that the isModified function expects 2 arguments: paths & modifiedPaths. Hence the error. Regression seems to have been introduced in 5.7.5 as 5.7.4 works fine

vkarpov15 added a commit that referenced this issue Oct 18, 2019
@vkarpov15 vkarpov15 added confirmed-bug We've confirmed this is a bug in Mongoose and will fix it. and removed needs repro script Maybe a bug, but no repro script. The issue reporter should create a script that demos the issue labels Oct 18, 2019
@vkarpov15
Copy link
Collaborator

Thanks for the repro script and sorry for the trouble, the fix will be in 5.7.6 👍

@saveman71
Copy link
Contributor

Thanks for the quick fix and thanks for being this reactive!

@carolinevk8
Copy link

I got the same problem. Is it a bug? If not then can you share the solution

@saveman71
Copy link
Contributor

If you're before 5.7.6 then upgrade (the fix is there) otherwise open a new issue!

@techinfo6789
Copy link

Getting same issue even though mine is "mongoose": "^6.6.5". can anyone pls share the solution

@saveman71
Copy link
Contributor

The solution was updating at the time. If this happens again, the as said earlier, you should open a new issue, so the maintainers see it better.

@Automattic Automattic locked and limited conversation to collaborators Oct 24, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
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

8 participants