MongoDB
 sql >> Database >  >> NoSQL >> MongoDB

Mongoose aggiorna gli array profondi

Ho finito per scorrere l'array:

Schemas.Client.findOne({ _id: id, 'customers._id': customerID }).select('customers.$.addresses').exec(function (err, client) {
  if (err) { return next(err); }
  if (!client) { return next(); }
  if (client.customers[0].addresses.length) {
    var addresses = client.customers[0].addresses;
    for (var i = 0; i < addresses.length; i++) {
      addresses[i].isDefault = false;
    }
    client.save(function (err) {
      if (err) { return next(err); }
      // finish
    });
  }
});