Effective way to handle large document

I have a large json object called jsonobj and the object have four property A, B, C and D.

I subscribe to the object on Template.onCreated.

In the template I need to loop out the four properties and therefore I have 4 helpers A, B, C and D.

In each helper I need to do a xxx.FindOne so I run a db question (mongodb) four times. As I can understand the question runs local and not on the server and maybe its just like pick the data from a local var (to do the db question).

But it feels anyway not as the most effective way to do it. Maybe I should run the question ones in some sort of init function or in the Template.onCreated and the put the result in four Reactive var or just one Reactive var for the whole document.

Any ideas on have to do it in the most effective way.

1 Like

Share code, and I’ll do my best to suggest improvements :wink:

It’s not much to share (or to much) to make it understandable, but thanks for your interest. The question is in a more general way and I have run into those thoughts several times. An other issue is also that if you don’t go to the database four times and instead store it in som var maybe it can be a memory issue if the object is large. I mean - the object is already stored in the local database.

if your colletion really big, you should probably consider if coupling them is necessary, and if I’d make more sense splitting your arrays into separate collections?

Iterating four properties isn’t that expensive, I think it will be fine. If you do run into memory issues at some point, you can always refactor :smile:

Hi. Thanks for your answer. Maybe I have excessive the documents size - it’s not so large. And iterating four properties must I do anyway independent of solution. The thing I am worry about most is that I am doing a database (local) question four times and the efficiency of that.

Running queries on the client is usually pretty quick. Honestly, if the UI doesn’t feel slow then don’t worry about it. Can also set a timer to measure how long it’s taking.

1 Like

to extend on @energistic’s nice answer, the client side queries and “database” is just powerful utility wrapped around a client side cache, and you should only worry about database calls that reach beyond the client :smile:

OK, thanks for your answer and I agree with both of you and I think I do it in the correct way by calling the db in each properties. If there are no efficiency (or very small) lost its the best place to do it and easiest to maintain.