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

Mongoose: Populating with projection using attribute of scheme #5132

Open
lmartinez12 opened this issue Mar 29, 2017 · 1 comment
Open

Mongoose: Populating with projection using attribute of scheme #5132

lmartinez12 opened this issue Mar 29, 2017 · 1 comment
Labels
new feature This change adds new functionality, like a new method or class

Comments

@lmartinez12
Copy link

I triying the following population/projection and work fine

  modelBaby.findOne({'userId': req.user.data._id, '_id': req.params.id})
  .populate('categories._categoryId', {
    levels:{
      $elemMatch:{
        name: 'PURPLE'
      }
    }
  })

But i need name as a variable something like:

modelBaby.findOne({'userId': req.user.data._id, '_id': req.params.id})
      .populate('categories._categoryId', {
        levels:{
          $elemMatch:{
            // over heree !!
            name: 'categories._levelName' or this._levelName
          }
        }
      })

the scheme ref is

const babyCategory = new mongoose.Schema(
      {
        answer: {type: String},
        _categoryId: {type: Schema.Types.ObjectId, required: true, ref: 'category'},
        _categoryName: {type: String, required: true},
        _levelName: {type: String, required: true}
      },
      {versionKey: false, _id : false}
    );

This is possible ? or how is the best way to approach this

Thanks btw =D

@sobafuchs
Copy link
Contributor

For now you would have to fetch it manually and match on it. I'll label this a feature request for 4.12

@sobafuchs sobafuchs added the new feature This change adds new functionality, like a new method or class label Apr 5, 2017
@sobafuchs sobafuchs added this to the 4.12 milestone Apr 5, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature This change adds new functionality, like a new method or class
Projects
None yet
Development

No branches or pull requests

2 participants