1

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.

Talha Awan
  • 4,573
  • 4
  • 25
  • 40
visconti
  • 45
  • 1
  • 5

0 Answers0