// Automigrates all data models
module.exports = function(app) {
  var Role = app.models.Role;
  var RoleMapping = app.models.RoleMapping;

	app.dataSources.mongo.automigrate(['User', 'AccessToken', 'RoleMapping', 'Role', 'ACL'], function(err) {
		if(err) throw err;
		
		app.dataSources.mongo.automigrate(['Checkpoint', 'Change', 'checkpoint'], function(err) {
			if(err) throw err;
			
			// 	Groups
			app.dataSources.mongo.automigrate('group', function(err) {
				if (err) throw err;
				
				// Auto-migrate sync for group (group-change)
				app.dataSources.mongo.automigrate('group-change', function(err) {
					if(err) throw err;
					
					// Mobile Users
					app.dataSources.mongo.automigrate('mobile_user', function(err) {
						if(err) throw err;
						
						// Mobile Users change
						app.dataSources.mongo.automigrate('mobile_user-change', function(err) {
							if(err) throw err;
							
							app.models.mobile_user.find({where: {'username': 'admin'}}, function(err, users) {
								if(users.length === 0) {
									app.models.mobile_user.create([{username: 'admin', password: 'password', email: 'admin@email.com'}], function(err, user) {
										Role.create({
											name: 'admin'
										}, function(err, role) {
											if (err) throw err;
											role.principals.create({
												principalType: RoleMapping.USER,
												principalId: user[0].id
											}, function(err, principal) {
												if (err) throw err;
							});
										});
									});
								}
							});
						});
					});
				});
			});
			
			// Position
			app.dataSources.mongo.automigrate('position', function(err) {
				if (err) throw err;
				
				// Migrate sync for mobile_user
				app.dataSources.mongo.automigrate('position-change', function(err) {
					if(err) throw err;
				});
			});
			
			// Weather Report
			app.dataSources.mongo.automigrate('weatherreport', function(err) {
				if (err) throw err;
				
				// Migrate sync for mobile_user
				app.dataSources.mongo.automigrate('weatherreport-change', function(err) {
					if(err) throw err;
				});
			});
			
			// Settings
			app.dataSources.mongo.automigrate('settings', function(err) {
				if (err) throw err;
				
				// Migrate sync for mobile_user
				app.dataSources.mongo.automigrate('settings-change', function(err) {
					if(err) throw err;
				});
			});
		});
	});	

};
@@ -156,28 +156,27 @@
 s.mongo.auto
-migr
+upd
 ate(%5B'User',
@@ -286,28 +286,27 @@
 s.mongo.auto
-migr
+upd
 ate(%5B'Checkp
@@ -414,36 +414,35 @@
 urces.mongo.auto
-migr
+upd
 ate('group', fun
@@ -559,28 +559,27 @@
 s.mongo.auto
-migr
+upd
 ate('group-c
@@ -676,36 +676,35 @@
 urces.mongo.auto
-migr
+upd
 ate('mobile_user
@@ -811,28 +811,27 @@
 s.mongo.auto
-migr
+upd
 ate('mobile_
@@ -1453,32 +1453,36 @@
 row err;%0A%09%09%09%09%09%09%09
+%09%09%09%09
 %7D);%0A%09%09%09%09%09%09%09%09%09%09%7D)
@@ -1591,36 +1591,35 @@
 urces.mongo.auto
-migr
+upd
 ate('position', 
@@ -1725,28 +1725,27 @@
 s.mongo.auto
-migr
+upd
 ate('positio
@@ -1856,36 +1856,35 @@
 urces.mongo.auto
-migr
+upd
 ate('weatherrepo
@@ -1995,28 +1995,27 @@
 s.mongo.auto
-migr
+upd
 ate('weather
@@ -2125,36 +2125,35 @@
 urces.mongo.auto
-migr
+upd
 ate('settings', 
@@ -2263,20 +2263,19 @@
 ngo.auto
-migr
+upd
 ate('set
@@ -2359,8 +2359,9 @@
 %7D);%09%0A%0A%7D;
+%0A

Use autoupdate instead of automigrate in server boot script to avoid losing data in MongoDB.