alexsk / mongoose-intl

Mongoose schema plugin for multilingual fields
MIT License
74 stars 31 forks source link

How to select a specific field from a document with mongoose-intl? #4

Closed shamim4063 closed 7 years ago

shamim4063 commented 7 years ago

My Schema Model like following:

import mongoose from 'mongoose';
import mongooseIntl from 'mongoose-intl';
import config from '../../../config/config.json';
var intlOptions = {
  languages: config.ALLOWED_LANGUAGES, // ["en", "bn"]
  defaultLanguage: config.DEFAULT_LANGUAGE // "en"
}
mongoose.plugin(mongooseIntl, intlOptions);

let authorSchema = new mongoose.Schema({
  name: {
    type: String, requiredAll: true, intl: true
  },
  description: {
    type: String, intl: true
  }
}, {
    toJSON: {
      virtuals: true
    }
  });

export default mongoose.model('Author', authorSchema);

I want to execute following query:

Author.setDefaultLanguage("bn");
        Author.find()
            .select({  name :1})
            .exec((err, author)=>{
                    if(err){
                            res.send(err)
                          }
                     res.json(author)
                });
            }) 

But it is not working. Without select block work perfectly.

alexsk commented 7 years ago

Thank you for reporting on this. The bugfix was published as v2.0.1