Working with data

Hi, I am developing a web project and using realm functions as my backend.

I learned that aggregation functions are more performance, because working with the data in its own environment without converting to an other language.

I wanted to write simple functions but it became so complex. I wonder whether there can be a better solution.

May be someone who looked at the aggregation functions in previous message can think that there are a lot of unnecessary query.

But actually I use aggregation functions in my updateOne or updateMany functions.

Your code is indeed very complicated and that is probably why you did not get any feedback.

What will be best is to share sample documents with real values together with the expected result. An array with a single empty string is not real data that may help understand your schema. Because an empty string looks a lot like another empty string. So if you have empty strings in the sample data and empty string in the result we would not know which one goes where. Ditto with _projectId:1 and _id:1, to illustrate your use-case you could make your projectId more complex string (_projectId:“project-todo-list”, _projectId:“contact-directory”) or reserve numbers from 100 to 199 for project id, then 1000 to 1099 for another set of _id. This way when we see 1013 in the sample result sets we know from where it comes. Seeing 1 and 2 in the result sets when all the sample ids you shared 1 and 2 in the sample data, we do not really know wich one is 1.

You could simplify you code by ensuring a constant schema. For example, by ensuring that customProjectSettings is always an array rather than allowing to be absent or null. There will be no need of $ifNull or $isArray because it will never be null and will always be an array.

Thanks for your comment, i will look at about creating constant schema.

1 Like