Redundant database info after every change [Solved]


#1

So being new to meteor and mongo in general, I’ve written some code to create the necessary collections in mongo and set up the structure, my issue is that after every change and save when the app resets it adds redundant data to the database. This results in the database growing after every change, my questions are, 1.Is this normal. 2.If it is normal am I going about database set up the wrong way and will the way I’m setting it up effect the project in the long term? Pseudo code below:

var List = [-Arbitrary list elements here-]; //all strings
var listLength = [5,15]; //split points in the list for something
collection1 = [];
collection2 = [];
for(i = 0; i < list.length; ++i) {
	var current = new Mongo.Collection(List[i]);
	Candidate.insert({  //All this fun stuff here is being added over and over to the current collection after every small change and save to the code.
			bio: {---Stuff Here--},
			experience: {---More Stuff--}
		});
	if(i < listLength[0]) {
		collection1[List[i]] = current; 
	}
	else {
		collection2[List[i]] = current; 
	}
}

#2

I you want to do one time modifications to the database, you can write a migration pattern like this on the server:

var Migrations = new Mongo.Collection("migration");

if (!Migrations.findOne({name:"oneTimeMigration"}){
  //do your database stuff
  Candidate.insert(....
  //and then insert that so that it doesn't happen again
  Migrations.insert({name:"oneTimeMigration"})
}

When you will upload your build to your production server, all your migrations will hapen one time and only one time.


#3

Wonderful, that solved my issue. Thanks a lot!