MongoDB
 sql >> Base de Dados >  >> NoSQL >> MongoDB

Matrizes profundas de atualização do Mongoose


Acabei apenas percorrendo o 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
    });
  }
});