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
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
})