buunguyen / mongoose-deep-populate

Mongoose plugin to enable deep population of nested models ⛺
MIT License
469 stars 44 forks source link

mongoose 4.0.1 Error: "Cannot read property 'prototype' of undefined" #25

Closed HellMagic closed 9 years ago

HellMagic commented 9 years ago

Flow the prompt to check the lib/plugin.js, then there is the code

  if (mongoose.Query.prototype.deepPopulate == null) {
    patchMongooseQuery(mongoose)
  }

but, as if there is no mongoose.Query object in mongoose 4.0.1(may be 4.x.x), so it throw error: "Cannot read property 'prototype' of undefined"--as the code, mongoose.Query not be checked if it is null。but the version @1.1.0 is work for mongoose 4.x.x, may be because the dependence is mongoose@>=3.6.0, but @2.0.0 the is depend on mongoose@>4.0.0 so, wish it is help, and expect to fix it , mongoose-deep-populate is awesome work~

buunguyen commented 9 years ago

Which version of Mongoose and mongoose-deep-populate are you using?

chuks commented 9 years ago

Hi, I am also seeing this problem. I just upgraded mongoose-deep-populate to 2.0.0 and it's having the same problem as above when used with mongoose 4.1.3 (latest as of now).

process.nextTick(function() { throw err; }) ^ TypeError: Cannot read property 'prototype' of undefined

Downgrading back to 1.1.0, until there is a fix. I tried to define it in the schema as a plugin, same as in 1.1.0, but I get that error. Please fix

buunguyen commented 9 years ago

Did you load mongoose-deep-populate correctly per 2.0 breaking change? That is:

var deepPopulate = require('mongoose-deep-populate')(mongoose)
chuks commented 9 years ago

Thanks ---I missed that. Should be in BIG BOLD RED letters! lol ;)

buunguyen commented 9 years ago

Agreed. I'll highlight that.