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

123
Views
How to migrate old Mongoose Schema data to new Mongoose Schema Data

My previous Mongoose Schema is

    social:{
    instagram: String,
    facebook: String,
    whatsapp: String,
    }

and my new Mongoose Schema is

    social:{
    instagram: {
    data: String,
            active: {
              type: Boolean,
              default: true
            }
    },
    facebook:{
    data: String,
            active: {
              type: Boolean,
              default: true
            }
    },
    whatsapp:{
    data: String,
            active: {
              type: Boolean,
              default: true
            }
    }
    }

so basically in previous model I am storing link directly in variable like instagram,facebook,whatsapp

but in new model , I am storing link in data variable under main variable and adding addtional active variable , so how can I move previous around 20 data in new format of schema

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You can do one update query that will transfer all documents to new structure. You can do it like this:

db.collection.update({
  "social.instagram.active": {
    "$exists": false
  }
},
[
  {
    "$set": {
      "social": {
        "instagram": {
          "data": "$social.instagram",
          "active": true
        },
        "facebook": {
          "data": "$social.facebook",
          "active": true
        },
        "whatsapp": {
          "data": "$social.whatsapp",
          "active": true
        }
      }
    }
  }
],
{
  "multi": true
})

Working example

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!