Closed eduolalo closed 9 years ago
Did you look at this? https://github.com/buunguyen/mongoose-deep-populate#v200
Yes, I'm passing the mongoose instance
Please post full code + stack trace. Would be great if it's executable to reproduce the error.
Model
var mongoose = require('mongoose');
var DeepPopulate = require('mongoose-deep-populate')(mongoose);
var Schema = mongoose.Schema;
var schema = {
//...
};
var UserSchema = new Schema(schema);
UserSchema.plugin(DeepPopulate);
module.exports = mongoose.model('User', UserSchema);
Code
User.findOne({
token: req.args.token
})
.deepPopulate('card.spendLimit card.spendLimit.thisDay card spendingCoach type company useType')
.exec(function(userErr, user) {
//...
});
Stack
TypeError: undefined is not a function\n at Object.module.exports.checkUser (/Users/christian/debito/debito-backend/lib/handler.js:70:10)\n at Object.module.exports.preread (/Users/christian/debito/debito-backend/lib/handler.js:120:18)\n at Layer.handle [as handle_request] (/Users/christian/debito/debito-backend/node_modules/express/lib/router/layer.js:82:5)\n at next (/Users/christian/debito/debito-backend/node_modules/express/lib/router/route.js:100:13)\n at Route.dispatch (/Users/christian/debito/debito-backend/node_modules/express/lib/router/route.js:81:3)\n at Layer.handle [as handle_request] (/Users/christian/debito/debito-backend/node_modules/express/lib/router/layer.js:82:5)\n at /Users/christian/debito/debito-backend/node_modules/express/lib/router/index.js:235:24\n at Function.proto.process_params (/Users/christian/debito/debito-backend/node_modules/express/lib/router/index.js:313:12)\n at /Users/christian/debito/debito-backend/node_modules/express/lib/router/index.js:229:12\n at Function.match_layer (/Users/christian/debito/debito-backend/node_modules/express/lib/router/index.js:296:3)\n at next (/Users/christian/debito/debito-backend/node_modules/express/lib/router/index.js:190:10)\n at /Users/christian/debito/debito-backend/node_modules/express/lib/router/index.js:192:16\n at Function.match_layer (/Users/christian/debito/debito-backend/node_modules/express/lib/router/index.js:296:3)\n at next (/Users/christian/debito/debito-backend/node_modules/express/lib/router/index.js:190:10)\n at /Users/christian/debito/debito-backend/node_modules/express/lib/router/index.js:192:16\n at Function.match_layer (/Users/christian/debito/debito-backend/node_modules/express/lib/router/index.js:296:3)\n at next (/Users/christian/debito/debito-backend/node_modules/express/lib/router/index.js:190:10)\n at /Users/christian/debito/debito-backend/node_modules/express/lib/router/index.js:192:16\n at Function.match_layer (/Users/christian/debito/debito-backend/node_modules/express/lib/router/index.js:296:3)\n at next (/Users/christian/debito/debito-backend/node_modules/express/lib/router/index.js:190:10)\n at /Users/christian/debito/debito-backend/index.js:116:9\n at Layer.handle [as handle_request] (/Users/christian/debito/debito-backend/node_modules/express/lib/router/layer.js:82:5)
Is not working when I try to chain as query, but it does when I use it as model statics
If you pass in the right instance of mongoose used by the app, I can't think of a reason why deepPopulate
isn't available in Query. It's not clear from the stack trace either (which BTW, you should have formatted more properly before posting). I suggest you debug your code, if you're sure it's a bug of the plugin, I'll take a look.
I did upgrade my mongoose module to v4.1.6, the upgrade mongoose-deep-populate and followed the instructions to register the plugin, then it throws me the this error in a code that was working in the v1.0.0 of this module
Error: TypeError: undefined is not a function\n at Object.module.exports.checkUser (/Users/christian/project/project-backend/lib/handler.js:70:10)
this is the code: