How to write meteor-migration script to insert a collection data to other collection ?
vsaran93 opened this issue · 1 comments
i need to insert one collection data to another collection. how can i write migration script for this purpose. card payments and corporate customer payment are two collections.
corporate customer payment collection has below attributes customerID,outsTanding,date,amount,headOfficeId,insertDate
cards collection has below attributes
customerID,amount,card,packageId,cardId,classType,expireDate,headOfficeId,insertDate
i'm inserting cards collection following datas to corporate customer collection.
CustomerID -> card.customerID
outsTanding -> card.cartId
date -> card.insertDate
amount -> card.amount
headOfficeId -> card.headOfficeId
so how can i apply this change for old datas. how need i write meteor migration for up and down.
anyone who had this issue assist me
thanks
i have found a solution for this issue i used percolate:migrations package
Migrations.add({
version: 2,
name: 'Insert card payment details to customer payments',
up: function() {
let cardDetails = Cards.find({}).map(function(k){
return k;
});
for(let k=0;k<cardDetails.length;k++){
let cusId = cardDetails[k].customerID;
let todayDate = cardDetails[k].expireDate;
let enteredAmount = parseFloat(cardDetails[k].card) +parseFloat(cardDetails[k].cash);
let packageId = cardDetails[k].packageId;
let headOfficeId = cardDetails[k].headOfficeId;
let insertDate = cardDetails[k].insertDate;
let author = cardDetails[k].author;
let createdAt = cardDetails[k].createdAt;
CustomersPayments.insert({customerID:cusId,outsTanding:0,date:todayDate,amount:enteredAmount,p
ackageID:packageId,headOfficeId:headOfficeId,insertDate:insertDate,author:author,createdAt:createdAt
});
}
},
name: 'Delete card payment details to customer payments,
down: function(){
/* Removing card payment details to customer payments */
CustomersPayments.remove({packageID: { $exists: true}});
}
});