I'm doing a project with Mongoose
in Node.js
. I have documents with this format:
{
username:"user1",
name:"joun",
books:[4,12,34,5,13]
}
I use find method for fetching them. it works but i have a problem. I want that get length of books
field rather than it's data. I did a lot's of research on web and find out Mongodb
and Mongoose
has some limitations in comparison of relation databases(there is no Join's). In the end i find two methods to do this but both of the i think are very slow and not optimum.
1- after fetching results, in a forEach
loop, calculate length of books
filed and replace that value with main value
2- after fetching results, using mongodb
Aggregation
framework i have to do some work to calculate that. but it seem this method is very expensive.
My server will be in heavy load and i think this two method's can be bottleneck for my architecture.
There is not any other option for me? i need faster and standard way to do it. some people say's you have to use a relational database like postgres but i cant. This is question for me that in lack of some functionalities like join
s in mongodb
, can we do every thing in proper way? my problem is an example!