【发布时间】:2014-07-28 19:52:12
【问题描述】:
我写了如下代码,并在mongo控制台上测试成功。
var up_results = db.upParts.find({"features.geometry": {$geoIntersects: {$geometry: {type: "Point", coordinates: [3, 5]}}}},{"_id":1, "features.properties.partID":1,"features.properties.connectedTo":1}).toArray();
var down_results = db.downParts.find({"features.geometry": {$geoIntersects: {$geometry: {type: "Point", coordinates: [-80, 30]}}}},{"_id":1, "features.properties.partID":1}).toArray();
var part_results = [];
for (i = 0; i < up_results.length; i++) {
for (j = 0; j < up_results[i].features[0].properties.connectedTo.length; j++) {
for (k = 0; k < down_results.length; k++) {
if (down_results[k]._id == up_results[i].features[0].properties.connectedTo[j]) {
part_results.push(db.parts.find({_id:{$in:[ObjectId(up_results[i].features[0].properties.partID)]}}));
}
}
}
}
parts_results.length;
我现在正在尝试在 nodejs 中实现它......但我认为我没有做对
我是这样开始的:
var up_results = null;
var down_results = null;
var part_results = [];
function geoqueries(callback) {
self.db.collection('upParts').find({"features.geometry": {$geoIntersects: {$geometry: {type: "Point", coordinates: [3, 5]}}}}, {"_id": 1, "features.properties.partID": 1, "features.properties.connectedTo": 1}).toArray(function (err, document) {
up_results = document;
});
self.db.collection('downParts').find({"features.geometry": {$geoIntersects: {$geometry: {type: "Point", coordinates: [-80, 30]}}}},{"_id":1, "features.properties.partID":1}).toArray(function(err, document2) {
down_results = document2;
});
callback();
}
function dosomething() {
...do something with up_results and down_results
}
geoqueries(dosomething);
我如何告诉 geoqueries() upParts 和 downParts 查找查询已完成?
【问题讨论】:
标签: javascript node.js asynchronous mongodb-query