title: Turf.js merge looks for features in GeoJSON
body: <p>I'm building a mapping app with Node.js.  We have about 40,000 polygons that display on the map so I'm trying to improve performance by merging them where possible.  Turf.js has a merge function that seems like the ticket.  I haven't been able to get it to work though.</p>
  
  <p>Here is the code where I'm trying to use turf in my controller.</p>
  
  <pre><code>var mongoose = require('mongoose');
  var bodyParser = require('body-parser');
  var turf = require('turf');
  var fs = require('fs');
  
  exports.show = function(req, res) {
    res.render('map', {
      title: 'Map'
    });
  };
  
  
  exports.postSearch = function(req, res) {
  
    // Bunch of query stuff goes into array below, (omitted for post)
  
    mongoose.model('Claim').find({
      $and:array
      }, function(err, polygons){
          // fs.writeFile('poly.txt', polygons);
          var test = turf.merge(polygons);
          res.json(test);
      });
  };
  </code></pre>
  
  <p>I put that fs.writeFile in there to get a sample of the geojson returned from mongodb.  This is what I get:</p>
  
  <pre><code>{
    properties: {
      TTLTPCD: 'CL',
      RNHCTRS: 389,
      TNRTPCD: 'C'
    },
    geometry: {
      coordinates: [
        [Object]
      ],
      type: 'Polygon'
    },
    type: 'Feature',
    _id: '56d2a2061c601e547e1099ee'
  }, {
    properties: {
      TTLTPCD: 'CS',
      RNHCTRS: 261,
      TNRTPCD: 'C'
    },
    geometry: {
      coordinates: [
        [Object]
      ],
      type: 'Polygon'
    },
    type: 'Feature',
    _id: '56d2a2071c601e547e109d37'
  },
  // this repeats a couple hundred times on my test query.
  </code></pre>
  
  <p>I get a stack trace but it doesn't make sense to me:</p>
  
  <pre><code>PROJECT_FOLDER/node_modules/turf/node_modules/turf-merge/index.js:55
    var merged = clone(polygons.features[0]),
                                        ^
  
  TypeError: Cannot read property '0' of undefined
      at Object.module.exports [as merge] (/media/ng/DATA/LighthouseLabs/ClaimMaps/nodeMaps/MapEmGems/node_modules/turf/node_modules/turf-merge/index.js:55:39)
      at Query.&lt;anonymous&gt; (/media/ng/DATA/LighthouseLabs/ClaimMaps/nodeMaps/MapEmGems/controllers/map.js:75:14)
      at /media/ng/DATA/LighthouseLabs/ClaimMaps/nodeMaps/MapEmGems/node_modules/kareem/index.js:177:19
      at /media/ng/DATA/LighthouseLabs/ClaimMaps/nodeMaps/MapEmGems/node_modules/kareem/index.js:109:16
      at doNTCallback0 (node.js:430:9)
      at process._tickCallback (node.js:359:13)
  </code></pre>
  
  <p>Turf seems to be looking for a features key in the geojson, but there is none.  Does anyone have a solution for this?</p>
  
  ###################### Edit after ghybs's answer
  
  <p>OK, ghybs sort of solved the geojson formatting issue.  I changed the last bit of the controller to this:</p>
  
  <pre><code>  mongoose.model('Claim').find({
      $and:array
      }, function(err, polygons){
          polygons = {
            type: "FeatureCollection",
            features: [polygons] };
          fs.writeFile('poly.txt', polygons);
          var test = turf.merge(polygons);
          fs.writeFile('test.txt', test);
          res.json(test);
      });
  };
  </code></pre>
  
  <p>I put a second fs.writeFile to see what turf.merge was returning.  The original geojson was not an array so I added the []'s.  No more turf error.  My map can't understand the output though.</p>
  
  <p>Now poly.txt gives me this:</p>
  
  <pre><code>[object Object]
  </code></pre>
  
  <p>and test.txt contains this:</p>
  
  <pre><code>{ properties: null,
    geometry: undefined,
    type: 'Feature',
    _id: '56d2a2061c601e547e1099ee',
    __v: undefined },{ properties: null,
    geometry: undefined,
    type: 'Feature',
    _id: '56d2a2071c601e547e109d37',
    __v: undefined },
  // This repeats 336 times
  </code></pre>
  
  <p>So I'm one step closer, I think.  Any ideas?  The map worked fine with the original data that was in poly.txt.  I'm trying to get the same thing but merged.</p>