Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

253
Visualizações
Localized Values are not updating in Mongoose/Node.JS

This is an odd issue I have been seeing. I have a mongoose schema using mongoose-i18n-localize:

var mongoose = require('mongoose');
var mongooseI18n = require('mongoose-i18n-localize');
var Schema = mongoose.Schema;

var TestSchema = new Schema({
  id: String,
  active: {type: Boolean, default: false},
  name: {type: String, required: true, i18n: true}
});

TestSchema.plugin(mongooseI18n, {
  locales: ['en_US']
});

module.exports = mongoose.model('Test', TestSchema);

In my call I have this:

app.put('/test/:id', function(req, res) {
  var query = {'id': req.params.id);
  var test = req.body;
  Test.findOneAndUpdate(query, test, function(err,p) {
    if (err) {
      handleError(res, err.message, "Failed to get information");
      console.log(err);
    } else {
      res.json(p);
    }
  })
});

and I passed in this data:

http://localhost:123/test/1d

{
  "active": true,
  "name": { "en_US": "test" }
}

I can change active to true and false with no issue. But the name never changes when I make a change. Also I get no error just does not update. Has anyone seen this before or know how to fix this so I can do localization.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

You should send the body using dot notation instead of brackets. It worked for me in this way:

{
  "active": true,
  "name.en_US": "test"
}
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda