You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Do you want to request a feature or report a bug?
Bug
What is the current behavior?
When trying to perform a virtual population of a field on an embedded discriminator, I receive the following error:
VM182 utils.js:214 Uncaught TypeError: Cannot read property 'length' of undefined
at getModelsMapForPopulate (/Users/Documents/Code/mongoose-test/node_modules/mongoose/lib/model.js:3462:24)
at populate (/Users/Documents/Code/mongoose-test/node_modules/mongoose/lib/model.js:3039:15)
at _populate (/Users/Documents/Code/mongoose-test/node_modules/mongoose/lib/model.js:3007:5)
at utils.promiseOrCallback.cb (/Users/Documents/Code/mongoose-test/node_modules/mongoose/lib/model.js:2980:5)
at Object.promiseOrCallback (/Users/Documents/Code/mongoose-test/node_modules/mongoose/lib/utils.js:211:14)
at Function.Model.populate (/Users/Documents/Code/mongoose-test/node_modules/mongoose/lib/model.js:2979:16)
at cb (/Users/Documents/Code/mongoose-test/node_modules/mongoose/lib/query.js:1325:17)
at result (/Users/Documents/Code/mongoose-test/node_modules/mongodb/lib/utils.js:413:17)
at executeCallback (/Users/Documents/Code/mongoose-test/node_modules/mongodb/lib/utils.js:405:9)
at handleCallback (/Users/Documents/Code/mongoose-test/node_modules/mongodb/lib/utils.js:128:55)
at self.close (/Users/Documents/Code/mongoose-test/node_modules/mongodb/lib/cursor.js:934:60)
at handleCallback (/Users/Documents/Code/mongoose-test/node_modules/mongodb/lib/utils.js:128:55)
at completeClose (/Users/Documents/Code/mongoose-test/node_modules/mongodb/lib/cursor.js:1073:14)
at Cursor.close (/Users/Documents/Code/mongoose-test/node_modules/mongodb/lib/cursor.js:1086:10)
at /Users/Documents/Code/mongoose-test/node_modules/mongodb/lib/cursor.js:934:21
at handleCallback (/Users/Documents/Code/mongoose-test/node_modules/mongodb-core/lib/cursor.js:178:5)
If the current behavior is a bug, please provide the steps to reproduce.
constmongoose=require('mongoose')mongoose.connect('mongodb://localhost/mongoosetest')mongoose.connection.once('open',()=>{constSchema=mongoose.Schema// Generate Users ModelconstuserSchema=newSchema({employeeId: Number,name: String})constUserModel=mongoose.model('Users',userSchema,'users')// Generate Embedded DiscriminatorsconsteventSchema=newSchema({message: String},{discriminatorKey: 'kind'});constbatchSchema=newSchema({events: [eventSchema]});constdocArray=batchSchema.path('events');// First embedded discriminator schemaconstclickedSchema=newSchema({element: {type: String},users: [Number]},{toJSON: {virtuals: true},toObject: {virtuals: true}});// Add virtual to first embedded discriminator schema for virtual populationclickedSchema.virtual('users_$',{ref: 'Users',localField: 'users',foreignField: 'employeeId'})constClicked=docArray.discriminator('Clicked',clickedSchema);// Second embedded discriminatorconstPurchased=docArray.discriminator('Purchased',newSchema({product: {type: String}}));constBatch=mongoose.model('EventBatch',batchSchema);// Generate Itemsconstuser={employeeId: 1,name: 'Test name'}constbatch={events: [{kind: 'Clicked',element: '#hero',message: 'hello',users: [1]},{kind: 'Purchased',product: 'action-figure-1',message: 'world'}]};Promise.all([UserModel.create(user),Batch.create(batch)]).then(function(){Batch.find({})// Populate virtual field of embedded discriminator.populate('events.users_$').lean().then(results=>console.log(results))})})
What is the expected behavior?
The query should not have errored and should have populated the virtual field.
Please mention your node.js, mongoose and MongoDB version.
node: v9.7.1, mongoose: 5.0.11, MongoDB: v3.2.5
The text was updated successfully, but these errors were encountered:
Do you want to request a feature or report a bug?
Bug
What is the current behavior?
When trying to perform a virtual population of a field on an embedded discriminator, I receive the following error:
If the current behavior is a bug, please provide the steps to reproduce.
What is the expected behavior?
The query should not have errored and should have populated the virtual field.
Please mention your node.js, mongoose and MongoDB version.
node: v9.7.1, mongoose: 5.0.11, MongoDB: v3.2.5
The text was updated successfully, but these errors were encountered: