Thursday, 25 May 2017

How to push array of objects on update mongoose

I tried something like this:

query:

query = {
      pictures: {$pushAll: files}
}

files array look like this:

[{ fieldname: 'productPhotos',
        originalname: 'images.jpg',
        encoding: '7bit',
        mimetype: 'image/jpeg',
        filename: '422e64cfb147eff02fee5166d63939b10564d4ad-images.jpg',
        }]

Update mongoose model:

 Product.update({ _id: product.productId}, query,...

Model look like this for pictures:

pictures: [{
        filename: {
            type: String,
            required: false
        }
    }],

Problem is array in database not update... Any solution?



via Vladimir

No comments:

Post a Comment