CityWebConsultants / Iris

Modular content management and web application framework built with Node.js and MongoDB
http://irisjs.org
Other
9 stars 7 forks source link

Extend mongo system #398

Closed adam-clarey closed 6 years ago

adam-clarey commented 6 years ago

This update adds the Point field type allowing for coordinate fields.

It also makes the dbCollections object global so that it can be used in modules for opperations other than just 'find' like the below example:

var dbConn = iris.dbCollections['forsale'];
  var aggregateQuery = [];

  if (params.coordinates) {
    aggregateQuery.push({
      '$geoNear' : {
        near: {
          type: 'Point',
          coordinates: params.coordinates
        },
        spherical: true,
        maxDistance: 2000,
        distanceMultiplier: 1,
        distanceField: 'distanceFromSource'
      }
    });
  }

  // Only properties from the last 2 years.
  params.query['date'] = {$gte: new Date(new Date().setFullYear(new Date().getFullYear() - 2)).toISOString()};

  if (params.query) {
    aggregateQuery.push({
      '$match' :  params.query
    });
  }

  var stream = dbConn.aggregate(aggregateQuery).allowDiskUse(true).cursor({ batchSize: 100000 }).exec();

  stream
  .on('data', function(result) {
      // Do stuff
  })
  .on('end', function() {
      // Do stuff
  })
  .on('error', function(err) {
    callback("There was a problem collecting results: " + err.message);
  });
facascante commented 6 years ago

all good.

i'm not allowed to merge sorry