process.env.NODE_ENV = process.env.NODE_ENV || 'development';
var MongoClient = require('mongodb').MongoClient
  , db_path = (process.env.NODE_ENV === 'production') ? process.env.MONGOLAB_URI : "mongodb://localhost/recycling_" + process.env.NODE_ENV
  ;


module.exports = {
  requiresDowntime: false, // true or false

  up: function(next) {
    MongoClient.connect(db_path, function(err, db){
      db.collection('locations').find({}, function(err, docs){
        var processDoc = function(err, doc) {
          if (doc === null) {
            next();
            return;
          }

          var geoJsonPoint = {
            type: 'Point',
            coordinates: doc.geoPoint
          }

          db.collection('locations').update(
            {_id: doc._id}, 
            {$set: {"geoJsonPoint": geoJsonPoint}, $unset: {"geoPoint": 1}}, 
          function(err){
            docs.nextObject(processDoc);
          })
        }

        docs.nextObject(processDoc);
      })
    });
  },

  down: function(next) {
    MongoClient.connect(db_path, function(err, db){
      db.collection('locations').find({}, function(err, docs){
        var processDoc = function(err, doc) {
          if (doc === null) {
            next();
            return;
          }

          var geoPoint = doc.geoJsonPoint.coordinates;

          db.collection('locations').update(
            {_id: doc._id}, 
            {$set: {"geoPoint": geoPoint}, $unset: {"geoJsonPoint": 1}}, 
          function(err){
            docs.nextObject(processDoc);
          })
        }

        docs.nextObject(processDoc);
      })
    });
  },

  test: function(){
    if (process.end.NODE_ENV !== 'test') {
      console.error("Please run migrate:test with `NODE_ENV=test`")
      return;
    }
    describe('up', function(){
      before(function(){})
      after(function(){})
      it('works');
    });

    describe('down', function(){
      before(function(){})
      after(function(){})
      it('works');
    });
  }
}

@@ -385,32 +385,68 @@
 (err, db)%7B%0A     
+ var counter = 0;%0A      var cursor =
  db.collection('
@@ -454,36 +454,56 @@
 ocations').find(
-%7B%7D, 
+)%0A%0A      cursor.toArray(
 function(err, do
@@ -519,129 +519,130 @@
     
-var processDoc = function(err, doc) %7B%0A          if (doc === null) %7B%0A            next();%0A            return;%0A      
+docs.forEach(function(doc, idx)%7B%0A          var geoJsonPoint = %7B%0A            type: 'Point',%0A            coordinates: %5B%0A
     
-%7D%0A%0A
     
@@ -647,36 +647,32 @@
         
-var geoJson
+doc.geo
 Point
- = %7B
+%5B0%5D,
 %0A       
@@ -672,38 +672,41 @@
             
-type: '
+  doc.geo
 Point
-',
+%5B1%5D
 %0A           
@@ -710,33 +710,9 @@
     
-coordinates: doc.geoPoint
+%5D
 %0A   
@@ -914,34 +914,92 @@
     
-docs.nextObject(
+if (idx %3E= docs.length - 1) %7B%0A              console.log(idx + %22 locations 
 process
-Doc
+ed%22
 );%0A 
@@ -1011,58 +1011,57 @@
     
-%7D)%0A        %7D%0A%0A        docs.nextObject(processDoc);
+    next();%0A            %7D%0A          %7D)%0A        %7D)
 %0A   
@@ -1058,32 +1058,33 @@
     %7D)%0A      %7D)%0A
+%0A
     %7D);%0A  %7D,%0A%0A  

Fix iteration over locations collection