I try since five hours to create a distance search with an precreated collection of cached cities in MongoDB with NodeJs + Mongoose. The data comes from opengeodb and fits fine in the collection, but when I try to process the data from my collection it seems some documents where not processed. I use the following to process it:
var citySchema = new Schema({
postalcode: String,
cityname: String,
state: String,
stateshort: String,
fiftykm: [String],
lat: Number,
lon: Number,
});
var city = mongoose.mdel('city', citySchema);
city.findOne({}).stream()
.on('error', function(err){
if(err) throw err;
})
.on('data', function(doc){
var tmp = doc.toObject();
city.findOne({postalcode : {$ne: tmp.postalcode}}).stream()
.on('error', function(err){ if(err) throw err;})
.on('data', function(compdoc){
var comptmp = compdoc.toObject();
if(distanz(tmp.lat, tmp.lon, comptmp.lat, comptmp.lon) < 50){
city.update({_id: tmp._id}, {$push: {fiftykm: comptmp.postalcode}},function(err, model){
if(err) throw err;
console.log(model);
});
}
});
})
.on('end', function(){
console.log('all done');
});
my tries debugging this with console.log() and tee, grep shows to me that some documents where not be called. I hope you can help me... or give me some other solution to do this at all 16480 documents
Thanks in advance!