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

223
Visualizações
Add a column in Mongodb collection

I have created a Db and a collection in Mongodb. All the items in the collection have the following attributes: name, city, car and year. I have around 200+ dummy items created in that collection. Now how do I go about adding 1 more attribute, like for example country for each item?

Is this possible in Mongodb?

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

0

you can use db.getCollection('collectionName').update(findQuery, updateQuery, upsert, multi) itself to insert a new column.

Example:

db.getCollection('test').update({}, {$set: {"country": "country"}},false,true)

This will insert a new column country with the default value country

over 4 years ago · Santiago Trujillo Relatório

0

Are you using something that maps your application's objects to the database documents? If that's the case, you might have to add the new attribute there.

If you're just talking about plain mongodb, you can just add it to documents that have that attribute. Or iterate over all the documents and add it with some default value. You might actually have to do this as "kind of migration" to if your code requires this attribute on all of your documents.

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