Skip to content

Instantly share code, notes, and snippets.

@chyld
Last active August 29, 2015 13:57
Show Gist options
  • Save chyld/9520378 to your computer and use it in GitHub Desktop.
Save chyld/9520378 to your computer and use it in GitHub Desktop.
exports.db = function(fn){
MongoClient.connect(mongoUrl, function(err, db) {
if(err){throw err;}
global.nss = {};
global.nss.db = db;
global.nss.db.collection('listings').ensureIndex({'coordinates':'2dsphere'}, function(err, indexName){
console.log('Connected to MongoDB');
fn();
});
});
};
listings.find({'coordinates':{$nearSphere:{$geometry:{type:'Point', coordinates:[loc.lat * 1, loc.lng * 1]}}, $maxDistance : 250000}}).toArray
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment