diff --git a/test/model.populate.test.js b/test/model.populate.test.js index 22626cc4cf5..94f56e49b10 100644 --- a/test/model.populate.test.js +++ b/test/model.populate.test.js @@ -4256,6 +4256,27 @@ describe('model: populate:', function() { }); }); + it('catchable error if localField or foreignField not specified (gh-6767)', function() { + const PersonSchema = new Schema({ + name: String, + band: String + }); + + const BandSchema = new Schema({ + name: String + }); + BandSchema.virtual('members'); + + const Person = db.model('gh6767_Person', PersonSchema); + const Band = db.model('gh6767_Band', BandSchema); + + return Band.create({ name: 'Motley Crue' }). + then(() => Band.find().populate('members')). + catch(error => { + assert.ok(error.message.indexOf('foreignField') !== -1, error.message); + }); + }); + it('source array', function(done) { var PersonSchema = new Schema({ name: String