Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

221
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!