This is my mongodb schema
var Client = new Schema({
name: String,
race: [{
name: String,
car: [{name: String}]
}]
});
I want to find a car by _id, something like this:
Client.findOne({
"race.car._id": req.body._id
}, {
"race.$.car": 1
}, function(err, client) {
//How to get the right car ?
client[ ? ].race[ ? ].car.name = "updated name";
//And sure, update the client
client.save();
});
But I don't know the best way, for the findOne and for the save.