最初に私のドキュメントの構造:
{
"_id": "541a8bea74123744b371d38e",
"geometry": {
"type": "Point",
"coordinates": [
5.3435,
51.69554
]
},
"type": "Feature",
"properties": {
}
}
問題は、forEach ループで update 関数を使用してフィールドを追加したいということです。ループは機能し、コレクション内のすべてのドキュメントを反復処理できますが、更新機能は何もしません。これは私が持っているものです:
var counter = 0;
collection.find({}, {
stream: true
})
.each(function(doc) {
counter++;
var hash = geohash.encode(doc.geometry.coordinates[1], doc.geometry.coordinates[0], precision = 9);
console.log("id: " + doc._id + " hash: " + hash + " counter= " + counter);
collection.update({
_id: doc._id
}, {
$set: {
"properties.geohash.precision9": hash
}
},
function(err) {
if (err) console.log(err);
}
);
})
.error(function(err) {
// handle error
console.log(err);
})
.success(function(doc) {
// final callback
console.log("added geohash");
res.send({
objects: doc
});
});
どこが間違っていますか?