Skip to content
Advertisement

Insert embeded document without reading whole document – spring, mongo

I have this factory collection :

JavaScript

which embeds the Product as products. When I have to add a product to an existing factory :

JavaScript

However, the issue is that product is a large object which contains a set of heavy attributes and the factory can have 2000 products.

So, the retrieved factory causes large memory consumption although it is not required in this phase. Is there a way to append a new product object directly into the factory document without reading the whole object?

EDIT:

As for the comments, I tried :

JavaScript

This gives error :

JavaScript

So I modified to convert it to a string before push :

JavaScript

This pushed object correctly but when reading :

JavaScript

Still, I got nowhere here. Any ideas on fixing this issue?

Advertisement

Answer

You should use MongoTemplate to update product with push to add to existing products. Something like

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement