I want to update collection's array, I have problems with finding object in collection's array and pushing new values to object, I tried few thing but then It seems I cannot use collection method on array?
router.post('/mountain_rescue_update', function(req, res) {
var collection = db.collection('rescuemodels');
var id = req.body.id;
collection.update({"type": "FeatureCollection"},function (err, doc) {
if (doc) {
doc.find({"features": []}, function (err, result) {
if (err) throw err;
res.send(result);
});
}
});
});
In FeatureCollection i have array features, i want to do find method on that array and find object by id and then make push if it is possible.
Actually How to find array? so some operations like find and update can be done on that array. I now that expression features: [] looks incorrectly but i don't have idea how to find it.
I tried something like this
collection.find({"features":{"properties":{"date":id}}}, function(err,doc){
console.log(doc);
}
If collection has one document which have array features? Shouldn't it work?
In mongodb i found
db.rescuemodels.find({"features.properties":{"title":"Wild Wolfs"}})
So it should look into collection features and give result of all objects which properties.title is Wild Wolfs?
My json
{
"_id" : ObjectId("54f50753a879d4e045b24878"),
"features" : [
{
"properties" : {
"title" : "Alona 45D",
"description" : "...",
"date" : ISODate("2015-03-03T01:00:40.842Z"),
"urgency" : "Low",
"phone" : "675 675 345",
"completion" : "NO",
"rescuer" : "Aleksander Gagarin"
},
"geometry" : {
"coordinates" : [
11.2637333,
23.1135565
],
"type" : "Point"
},
"type" : "Feature"
},...etc
],
"type" : "FeatureCollection",
"__v" : 0
}
Ok I succeeded with finding object in document's array, So now just replacing some properties left.
db.rescuemodels.find({"type":"FeatureCollection"},{"features": {$elemMatch:{"properties.title":"W"}}})
Maybe somebody know how to make this statement ok
db.rescuemodels.update({"type":"FeatureCollection"},{"features":{$elemMatch:{"properties.title":"W"}}},{$set:{"features":{"properties":{"title":"XXX"}}}})