necesito hacer update a un documento que se llama 'storage' que se encuentra en una array de objetos,sin embargo dentro del documento storage tengo una array de objetos llamado client, que no quiero modificar. sin embargo al hacer el update se actualiza todo el documento de 'storage'. borrando lo que tengo en 'client'. alguien sabe alguna solución?
estructura del documento
rut: {
type: String,
lowercase: true,
unique: true
},
name: String,
address: {
name: String,
region: String,
commune: String,
},
phone: String,
type: Boolean,
status: Boolean,
storage: [{
code: String, //4-6 required
name: String, //4-255 required
address: {
name: String, //4-255 required
region: String, //required
commune: String, //required
},
status: Boolean, //required
equipment: [{
type: shema.ObjectId,
ref: 'equipments'
}],
requests: [{
type: shema.ObjectId,
ref: 'requests'
}],
technicals: [{
_id: {
type: shema.ObjectId,
ref: 'employees'
}
}],
client: [{
rut: String,
name: String,
pLastName: String,
mLastName: String,
email: String,
phone: [{
type: Number
}],
password: String,
role: {
type: shema.ObjectId,
ref: 'roles',
},
status: Boolean
}]
}]
funcion de actualizacion: tengo la idea de que el problema puede ser el arrayFilter, sin embargo no encuentro otra manera eficiente de poder hacer una actualizacion.
function updateStorage(_idCompany, _idStorage, storage) { //funcion que agrega un objeto de bodega nuevo al _id empresa asociado
return new Promise(async (resolve, reject) => {
try {
await model.update({'_id': _idCompany},{'storage.$[stor]':storage},{arrayFilters: [{ "stor._id": { $eq: _idStorage } }]})
.then(dataResult=>{
resolve(dataResult)
})
.catch(err => {
reject(boom.conflict('there was a conflict', err.message))
})
} catch (err) {
reject(boom.expectationFailed('expected this to work', err.message));
}
})
}
storage
sin sustituir el campoclient
, correcto?