alexsk / mongoose-intl

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

multiuser environment setDefaultLanguage break #17

Open kalicki opened 5 years ago

kalicki commented 5 years ago

Hey @alexsk, thanks for this plugin.

I have a problem with setDefaultLanguage for multiuser, your example dont work and setDefault for all models and not only this request by user.

// Set language
      Tag.find({}, function (_err, posts) {
        mongoose.setDefaultLanguage(lang);
        return res.status(200).send(posts);
      });

the last language set to be for everyone is the latest sent in lang

kalicki commented 5 years ago

Async/Await, pseudo solution (maybe bad):

// Create query
      const elementRecipe = await Recipe.find(query.filter).sort(query.sort);

      // Set languages on values
      if (lang) {
        // return all elements only the lang requested
        elementRecipe.map(values => {
          values.setLanguage(lang);
        });
      }