Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Document.prototype.populate() options.retainNullValues not working. #8293

Closed
bongjinpark1 opened this issue Oct 31, 2019 · 0 comments
Closed
Labels
has repro script There is a repro script, the Mongoose devs need to confirm that it reproduces the issue
Milestone

Comments

@bongjinpark1
Copy link

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 = Team

cards.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 = Card

index.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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
has repro script There is a repro script, the Mongoose devs need to confirm that it reproduces the issue
Projects
None yet
Development

No branches or pull requests

2 participants