Hello,
In this case I do not need to filter since I would like to add a new unique and different objectid to each of the documents, within the “product” array even if it contains more than one object:
With the provided script I share an example of the result:
[
{
_id: ObjectId('66340d52b5896b0ea5eddpl7'),
idEstatus: Long('1'),
idTipoVenta: 2,
productos: [
{
codigoTipo: 'C',
idOrigen: 2,
nombre: 'Producto 2',
precio: 123.12,
new_id: ObjectId('66340da3b5896b0ea5eddcf7')
}
]
},
{
_id: ObjectId('66340d52b5896b0ea5eddyy7'),
idEstatus: Long('1'),
idTipoVenta: 2,
productos: [
{
codigoTipo: 'C',
idOrigen: 2,
nombre: 'Silla',
precio: 131.23,
new_id: ObjectId('66340da3b5896b0ea5eddcf7')
},
{
codigoTipo: 'C',
idOrigen: 2,
nombre: 'Mesa',
precio: 250
},
{
codigoTipo: 'C',
idOrigen: 2,
nombre: 'Ropero',
precio: 5000
}
]
},
{
_id: ObjectId('66340d52b5896b0ea5eddss7'),
idEstatus: Long('1'),
idTipoVenta: 2,
productos: [
{
codigoTipo: 'C',
idOrigen: 2,
nombre: 'Producto 1',
precio: 1231.23,
new_id: ObjectId('66340da3b5896b0ea5eddcf7')
}
]
},
{
_id: ObjectId('66340d52b5896b0ea5edddd6'),
idEstatus: Long('1'),
idTipoVenta: 2,
productos: [
{
codigoTipo: 'C',
idOrigen: 2,
nombre: 'Producto 3',
precio: 0.11,
new_id: ObjectId('66340da3b5896b0ea5eddcf7')
}
]
}
]
);
I would like this ObjectId to be different for each object and be assigned to all of them since some are left empty in the example of the array that contains 3 objects.
Thanks for your help.