-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Closed
Labels
has repro scriptThere is a repro script, the Mongoose devs need to confirm that it reproduces the issueThere is a repro script, the Mongoose devs need to confirm that it reproduces the issue
Milestone
Description
nodejs version : 10.16.3
mongooser version : 5.7.7
teams.js
const mongoose = require('mongoose')
const fields = {
troops: [{ type: Number, ref: 'Card' }]
}
const options = {
versionKey: false,
timestamps: true
}
const schema = new mongoose.Schema(fields, options)
const Team = mongoose.model('Team', schema)
module.exports = Teamcards.js
const mongoose = require('mongoose')
const fields = {
_id: { type: Number },
name: { type: String, unique: true },
entityType: { type: String }
}
const options = {
discriminatorKey: 'entityType'
}
const schema = new mongoose.Schema(fields, options)
const Card = mongoose.model('Card', schema)
module.exports = Cardindex.js
const Team = require('path of teams.js')
const team = new Team({
troops: [1, 2, 3, 4]
})
await team.save()
await team
.populate([
{
path: 'troops',
select: 'name',
retainNullValues: true, // not working
options: {
retainNullValues: true // not working too.
}
}
])
.execPopulate()
console.log(team)
/*
expected:
{
troops: [null, {name: 'name of 2'}, {name: 'name of 3'}, {name: 'name of 4'}]
}
actual:
{
troops: [{name: 'name of 2'}, {name: 'name of 3'}, {name: 'name of 4'}]
}
*/How can i get populated array include null value? any ideas?
thanks.
Metadata
Metadata
Assignees
Labels
has repro scriptThere is a repro script, the Mongoose devs need to confirm that it reproduces the issueThere is a repro script, the Mongoose devs need to confirm that it reproduces the issue